Remove toolset plugin
This commit is contained in:
@@ -1,218 +0,0 @@
|
||||
<?php
|
||||
// Generated by ZF2's ./bin/classmap_generator.php
|
||||
return array(
|
||||
'Enlimbo_Forms_Wpcf' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/forms.php',
|
||||
'Toolset_Filesystem_Directory' => dirname( __FILE__ ) . '/../vendor/toolset/filesystem/directory.php',
|
||||
'Toolset_Filesystem_Exception' => dirname( __FILE__ ) . '/../vendor/toolset/filesystem/exception.php',
|
||||
'Toolset_Filesystem_File' => dirname( __FILE__ ) . '/../vendor/toolset/filesystem/file.php',
|
||||
'Types_Admin' => dirname( __FILE__ ) . '/controllers/admin.php',
|
||||
'Types_Admin_Edit_Custom_Fields_Group' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.edit.custom.fields.group.php',
|
||||
'Types_Admin_Edit_Fields' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.edit.fields.php',
|
||||
'Types_Admin_Edit_Meta_Fields_Group' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.edit.meta.fields.group.php',
|
||||
'Types_Admin_Edit_Post_Type' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.edit.post.type.php',
|
||||
'Types_Admin_Edit_Taxonomy' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.edit.taxonomy.php',
|
||||
'Types_Admin_Fields' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.fields.php',
|
||||
'Types_Admin_Menu' => dirname( __FILE__ ) . '/controllers/admin_menu.php',
|
||||
'Types_Admin_Page' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.page.php',
|
||||
'Types_Admin_Post_Type' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.post-type.php',
|
||||
'Types_Admin_Post_Types_List_Table' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.post.types.list.table.php',
|
||||
'Types_Admin_Taxonomies' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.taxonomies.php',
|
||||
'Types_Admin_Taxonomies_List_Table' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.taxonomies.list.table.php',
|
||||
'Types_Admin_Usermeta_Control_Table' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.usermeta.table.php',
|
||||
'Types_Admin_Usermeta_Groups_List_Table' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.admin.usermeta.groups.list.table.php',
|
||||
'Types_Ajax' => dirname( __FILE__ ) . '/controllers/ajax.php',
|
||||
'Types_Ajax_Handler_Abstract' => dirname( __FILE__ ) . '/controllers/ajax/handler/abstract.php',
|
||||
'Types_Ajax_Handler_Check_Slug_Conflicts' => dirname( __FILE__ ) . '/controllers/ajax/handler/check_slug_conflicts.php',
|
||||
'Types_Ajax_Handler_Field_Control_Action' => dirname( __FILE__ ) . '/controllers/ajax/handler/field_control_action.php',
|
||||
'Types_Ajax_Handler_Interface' => dirname( __FILE__ ) . '/controllers/ajax/handler_interface.php',
|
||||
'Types_Ajax_Handler_Settings_Action' => dirname( __FILE__ ) . '/controllers/ajax/handler/settings_action.php',
|
||||
'Types_Api' => dirname( __FILE__ ) . '/controllers/api.php',
|
||||
'Types_Api_Handler_Filter_Get_Field_Group_Ids_By_Post_Type' => dirname( __FILE__ ) . '/controllers/api/handler/filter_get_field_group_ids_by_post_type.php',
|
||||
'Types_Api_Handler_Import_From_Zip_File' => dirname( __FILE__ ) . '/controllers/api/handler/import_from_zip_file.php',
|
||||
'Types_Api_Handler_Interface' => dirname( __FILE__ ) . '/controllers/api/handler/interface.php',
|
||||
'Types_Api_Handler_Query_Groups' => dirname( __FILE__ ) . '/controllers/api/handler/query_groups.php',
|
||||
'Types_Asset_Help_Tab_Loader' => dirname( __FILE__ ) . '/controllers/asset/help_tab_loader.php',
|
||||
'Types_Asset_Manager' => dirname( __FILE__ ) . '/controllers/asset/manager.php',
|
||||
'Types_Assets' => dirname( __FILE__ ) . '/controllers/assets.php',
|
||||
'Types_Dialog_Box' => dirname( __FILE__ ) . '/controllers/dialog_box.php',
|
||||
'Types_Embedded' => dirname( __FILE__ ) . '/controllers/embedded.php',
|
||||
'Types_Field_Group' => dirname( __FILE__ ) . '/models/field/group.php',
|
||||
'Types_Field_Group_Factory' => dirname( __FILE__ ) . '/models/field/group/factory.php',
|
||||
'Types_Field_Group_Post' => dirname( __FILE__ ) . '/models/field/group/post.php',
|
||||
'Types_Field_Group_Post_Factory' => dirname( __FILE__ ) . '/models/field/group/post_factory.php',
|
||||
'Types_Field_Group_Term' => dirname( __FILE__ ) . '/models/field/group/term.php',
|
||||
'Types_Field_Group_Term_Factory' => dirname( __FILE__ ) . '/models/field/group/term_factory.php',
|
||||
'Types_Field_Group_User' => dirname( __FILE__ ) . '/models/field/group/user.php',
|
||||
'Types_Field_Group_User_Factory' => dirname( __FILE__ ) . '/models/field/group/user_factory.php',
|
||||
'Types_Fields_Conditional' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.types.fields.conditional.php',
|
||||
'Types_Field_Type_Converter' => dirname( __FILE__ ) . '/controllers/field/type_converter.php',
|
||||
'Types_Field_Type_Definition_Checkbox' => dirname( __FILE__ ) . '/models/field/gateway/checkbox.php',
|
||||
'Types_Field_Type_Definition_Checkboxes' => dirname( __FILE__ ) . '/models/field/gateway/checkboxes.php',
|
||||
'Types_Field_Type_Definition_Date' => dirname( __FILE__ ) . '/models/field/gateway/date.php',
|
||||
'Types_Field_Type_Definition' => dirname( __FILE__ ) . '/models/field/type/definition.php',
|
||||
'Types_Field_Type_Definition_Factory' => dirname( __FILE__ ) . '/models/field/type/definition_factory.php',
|
||||
'Types_Field_Type_Definition_Numeric' => dirname( __FILE__ ) . '/models/field/gateway/numeric.php',
|
||||
'Types_Field_Type_Definition_Radio' => dirname( __FILE__ ) . '/models/field/gateway/radio.php',
|
||||
'Types_Field_Type_Definition_Select' => dirname( __FILE__ ) . '/models/field/gateway/select.php',
|
||||
'Types_Field_Type_Definition_Singular' => dirname( __FILE__ ) . '/models/field/gateway/singular.php',
|
||||
'Types_Field_Utils' => dirname( __FILE__ ) . '/controllers/field/utils.php',
|
||||
'Types_Frontend' => dirname( __FILE__ ) . '/controllers/frontend.php',
|
||||
'Types_Helper_Condition_Archive_Exists' => dirname( __FILE__ ) . '/models/helper/condition/archive/exists.php',
|
||||
'Types_Helper_Condition_Archive_Has_Fields' => dirname( __FILE__ ) . '/models/helper/condition/archive/has_fields.php',
|
||||
'Types_Helper_Condition_Archive_Missing' => dirname( __FILE__ ) . '/models/helper/condition/archive/missing.php',
|
||||
'Types_Helper_Condition_Archive_No_Fields' => dirname( __FILE__ ) . '/models/helper/condition/archive/no_fields.php',
|
||||
'Types_Helper_Condition_Archive_No_Support' => dirname( __FILE__ ) . '/models/helper/condition/archive/no_support.php',
|
||||
'Types_Helper_Condition_Archive_Support' => dirname( __FILE__ ) . '/models/helper/condition/archive/support.php',
|
||||
'Types_Helper_Condition_Cred_Active' => dirname( __FILE__ ) . '/models/helper/condition/cred/active.php',
|
||||
'Types_Helper_Condition_Cred_Forms_Exist' => dirname( __FILE__ ) . '/models/helper/condition/cred/forms_exist.php',
|
||||
'Types_Helper_Condition_Cred_Forms_Missing' => dirname( __FILE__ ) . '/models/helper/condition/cred/forms_missing.php',
|
||||
'Types_Helper_Condition_Cred_Missing' => dirname( __FILE__ ) . '/models/helper/condition/cred/missing.php',
|
||||
'Types_Helper_Condition' => dirname( __FILE__ ) . '/models/helper/condition.php',
|
||||
'Types_Helper_Condition_Layouts_Active' => dirname( __FILE__ ) . '/models/helper/condition/layouts/active.php',
|
||||
'Types_Helper_Condition_Layouts_Archive_Exists' => dirname( __FILE__ ) . '/models/helper/condition/layouts/archive_exists.php',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing' => dirname( __FILE__ ) . '/models/helper/condition/layouts/archive_missing.php',
|
||||
'Types_Helper_Condition_Layouts_Compatible' => dirname( __FILE__ ) . '/models/helper/condition/layouts/compatible.php',
|
||||
'Types_Helper_Condition_Layouts_Missing' => dirname( __FILE__ ) . '/models/helper/condition/layouts/missing.php',
|
||||
'Types_Helper_Condition_Layouts_Template_Exists' => dirname( __FILE__ ) . '/models/helper/condition/layouts/template_exists.php',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing' => dirname( __FILE__ ) . '/models/helper/condition/layouts/template_missing.php',
|
||||
'Types_Helper_Condition_Screen' => dirname( __FILE__ ) . '/models/helper/condition/screen.php',
|
||||
'Types_Helper_Condition_Single_Exists' => dirname( __FILE__ ) . '/models/helper/condition/single/exists.php',
|
||||
'Types_Helper_Condition_Single_Has_Fields' => dirname( __FILE__ ) . '/models/helper/condition/single/has_fields.php',
|
||||
'Types_Helper_Condition_Single_Missing' => dirname( __FILE__ ) . '/models/helper/condition/single/missing.php',
|
||||
'Types_Helper_Condition_Single_No_Fields' => dirname( __FILE__ ) . '/models/helper/condition/single/no_fields.php',
|
||||
'Types_Helper_Condition_Template' => dirname( __FILE__ ) . '/models/helper/condition/template.php',
|
||||
'Types_Helper_Condition_Type_Fields_Assigned' => dirname( __FILE__ ) . '/models/helper/condition/type/fields_assigned.php',
|
||||
'Types_Helper_Condition_Type_No_Post_Or_Page' => dirname( __FILE__ ) . '/models/helper/condition/type/no_post_or_page.php',
|
||||
'Types_Helper_Condition_Type_Post_Or_Page' => dirname( __FILE__ ) . '/models/helper/condition/type/post_or_page.php',
|
||||
'Types_Helper_Condition_Views_Active' => dirname( __FILE__ ) . '/models/helper/condition/views/active.php',
|
||||
'Types_Helper_Condition_Views_Archive_Exists' => dirname( __FILE__ ) . '/models/helper/condition/views/archive_exists.php',
|
||||
'Types_Helper_Condition_Views_Archive_Missing' => dirname( __FILE__ ) . '/models/helper/condition/views/archive_missing.php',
|
||||
'Types_Helper_Condition_Views_Missing' => dirname( __FILE__ ) . '/models/helper/condition/views/missing.php',
|
||||
'Types_Helper_Condition_Views_Template_Exists' => dirname( __FILE__ ) . '/models/helper/condition/views/template_exists.php',
|
||||
'Types_Helper_Condition_Views_Template_Missing' => dirname( __FILE__ ) . '/models/helper/condition/views/template_missing.php',
|
||||
'Types_Helper_Condition_Views_Views_Exist' => dirname( __FILE__ ) . '/models/helper/condition/views/views_exist.php',
|
||||
'Types_Helper_Condition_Views_Views_Missing' => dirname( __FILE__ ) . '/models/helper/condition/views/views_missing.php',
|
||||
'Types_Helper_Create_Content_Template' => dirname( __FILE__ ) . '/models/helper/create/content_template.php',
|
||||
'Types_Helper_Create_Form' => dirname( __FILE__ ) . '/models/helper/create/form.php',
|
||||
'Types_Helper_Create_Layout' => dirname( __FILE__ ) . '/models/helper/create/layout.php',
|
||||
'Types_Helper_Create_View' => dirname( __FILE__ ) . '/models/helper/create/view.php',
|
||||
'Types_Helper_Create_Wordpress_Archive' => dirname( __FILE__ ) . '/models/helper/create/wordpress_archive.php',
|
||||
'Types_Helper_Output_Interface' => dirname( __FILE__ ) . '/models/helper/output/interface.php',
|
||||
'Types_Helper_Output_Meta_Box' => dirname( __FILE__ ) . '/models/helper/output/meta_box.php',
|
||||
'Types_Helper_Placeholder' => dirname( __FILE__ ) . '/models/helper/placeholder.php',
|
||||
'Types_Helper_Twig' => dirname( __FILE__ ) . '/models/helper/twig.php',
|
||||
'Types_Helper_Url' => dirname( __FILE__ ) . '/models/helper/url.php',
|
||||
'Types_Import_Export' => dirname( __FILE__ ) . '/controllers/import_export.php',
|
||||
'Types_Information_Container' => dirname( __FILE__ ) . '/models/information/container.php',
|
||||
'Types_Information_Controller' => dirname( __FILE__ ) . '/controllers/information/controller.php',
|
||||
'Types_Information_Message' => dirname( __FILE__ ) . '/models/information/message.php',
|
||||
'Types_Information_Message_Post_Type' => dirname( __FILE__ ) . '/models/information/message/post_type.php',
|
||||
'Types_Information_Table' => dirname( __FILE__ ) . '/models/information/table.php',
|
||||
'Types_Interop_Handler_Divi' => dirname( __FILE__ ) . '/controllers/interop/handler/divi.php',
|
||||
'Types_Interop_Handler_Interface' => dirname( __FILE__ ) . '/controllers/interop/handler_interface.php',
|
||||
'Types_Interop_Handler_The7' => dirname( __FILE__ ) . '/controllers/interop/handler/the7.php',
|
||||
'Types_Interop_Handler_Use_Any_Font' => dirname( __FILE__ ) . '/controllers/interop/handler/use_any_font.php',
|
||||
'Types_Interop_Handler_Wpml' => dirname( __FILE__ ) . '/controllers/interop/handler/wpml.php',
|
||||
'Types_Interop_Mediator' => dirname( __FILE__ ) . '/controllers/interop/mediator.php',
|
||||
'Types_Main' => dirname( __FILE__ ) . '/controllers/main.php',
|
||||
'Types_Page_Abstract' => dirname( __FILE__ ) . '/controllers/page/abstract.php',
|
||||
'Types_Page_Dashboard' => dirname( __FILE__ ) . '/controllers/page/dashboard.php',
|
||||
'Types_Page_Extension_Edit_Post' => dirname( __FILE__ ) . '/controllers/page/extension/edit_post.php',
|
||||
'Types_Page_Extension_Edit_Post_Fields' => dirname( __FILE__ ) . '/controllers/page/extension/edit_post_fields.php',
|
||||
'Types_Page_Extension_Edit_Post_Type' => dirname( __FILE__ ) . '/controllers/page/extension/edit_post_type.php',
|
||||
'Types_Page_Extension_Settings' => dirname( __FILE__ ) . '/controllers/page/extension/settings.php',
|
||||
'Types_Page_Field_Control' => dirname( __FILE__ ) . '/controllers/page/field_control.php',
|
||||
'Types_Page_Hidden_Helper' => dirname( __FILE__ ) . '/controllers/page/hidden/helper.php',
|
||||
'Types_Post_Type' => dirname( __FILE__ ) . '/models/post_type.php',
|
||||
'Types_Setting_Boolean' => dirname( __FILE__ ) . '/models/setting/boolean.php',
|
||||
'Types_Setting' => dirname( __FILE__ ) . '/models/setting.php',
|
||||
'Types_Setting_Interface' => dirname( __FILE__ ) . '/models/setting/interface.php',
|
||||
'Types_Setting_Option' => dirname( __FILE__ ) . '/models/setting/option.php',
|
||||
'Types_Setting_Option_Interface' => dirname( __FILE__ ) . '/models/setting/option/interface.php',
|
||||
'Types_Setting_Preset_Information_Table' => dirname( __FILE__ ) . '/models/setting/preset/information_table.php',
|
||||
'Types_Taxonomy' => dirname( __FILE__ ) . '/models/taxonomy.php',
|
||||
'Types_Twig_Autoloader' => dirname( __FILE__ ) . '/controllers/twig_autoloader.php',
|
||||
'Types_Upgrade' => dirname( __FILE__ ) . '/controllers/upgrade.php',
|
||||
'Types_Utils' => dirname( __FILE__ ) . '/controllers/admin_notice/utils.php',
|
||||
'Types_Admin_Notices_Free_Version' => dirname( __FILE__ ) . '/controllers/admin_notice/free-version.php',
|
||||
'Types_Utils_Post_Type_Option' => dirname( __FILE__ ) . '/controllers/utils/post_type_option.php',
|
||||
'Types_Wpml_Field_Group' => dirname( __FILE__ ) . '/models/wpml/field_group.php',
|
||||
'Types_Wpml_Field_Group_String_Description' => dirname( __FILE__ ) . '/models/wpml/field/group/string/description.php',
|
||||
'Types_Wpml_Field_Group_String' => dirname( __FILE__ ) . '/models/wpml/field/group/string.php',
|
||||
'Types_Wpml_Field_Group_String_Name' => dirname( __FILE__ ) . '/models/wpml/field/group/string/name.php',
|
||||
'Types_Wpml_Interface' => dirname( __FILE__ ) . '/models/wpml/interface.php',
|
||||
'Wpcf_Cake_Validation' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/validation-cakephp.php',
|
||||
'WPCF_Conditional' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/conditional.php',
|
||||
'WPCF_Custom_Fields_List_Table' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.wpcf.custom.fields.list.table.php',
|
||||
'WPCF_Editor' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/editor.php',
|
||||
'WPCF_Evaluate' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/evaluate.php',
|
||||
'WPCF_Field_Accessor_Abstract' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/accessor/abstract.php',
|
||||
'WPCF_Field_Accessor_Dummy' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/accessor/dummy.php',
|
||||
'WPCF_Field_Accessor_Termmeta' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/accessor/termmeta.php',
|
||||
'WPCF_Field_Accessor_Termmeta_Field' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/accessor/termmeta_field.php',
|
||||
'WPCF_Field_DataMapper_Abstract' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/datamapper/abstract.php',
|
||||
'WPCF_Field_DataMapper_Checkbox' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/datamapper/checkbox.php',
|
||||
'WPCF_Field_DataMapper_Checkboxes' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/datamapper/checkboxes.php',
|
||||
'WPCF_Field_DataMapper_Identity' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/datamapper/identity.php',
|
||||
'WPCF_Field_Data_Saver' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/data_saver.php',
|
||||
'WPCF_Field_Definition_Abstract' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_abstract.php',
|
||||
'WPCF_Field_Definition' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition.php',
|
||||
'WPCF_Field_Definition_Factory' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_factory.php',
|
||||
'WPCF_Field_Definition_Factory_Post' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_factory_post.php',
|
||||
'WPCF_Field_Definition_Factory_Term' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_factory_term.php',
|
||||
'WPCF_Field_Definition_Factory_User' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_factory_user.php',
|
||||
'WPCF_Field_Definition_Generic' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_generic.php',
|
||||
'WPCF_Field_Definition_Post' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_post.php',
|
||||
'WPCF_Field_Definition_Term' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_term.php',
|
||||
'WPCF_Field_Definition_User' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/definition_user.php',
|
||||
'WPCF_Field' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field.php',
|
||||
'WPCF_Field_Hooks_API' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/hooks_api.php',
|
||||
'WPCF_Field_Instance_Abstract' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/instance_abstract.php',
|
||||
'WPCF_Field_Instance' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/instance.php',
|
||||
'WPCF_Field_Instance_Term' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/instance_term.php',
|
||||
'WPCF_Field_Instance_Unsaved' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/instance_unsaved.php',
|
||||
'WPCF_Field_Option_Checkboxes' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/option_checkboxes.php',
|
||||
'WPCF_Field_Option_Radio' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/option_radio.php',
|
||||
'WPCF_Field_Option_Select' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/option_select.php',
|
||||
'WPCF_Field_Renderer_Abstract' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/abstract.php',
|
||||
'WPCF_Field_Renderer_Factory' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/factory.php',
|
||||
'WPCF_Field_Renderer_Preview_Address' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/address.php',
|
||||
'WPCF_Field_Renderer_Preview_Base' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/base.php',
|
||||
'WPCF_Field_Renderer_Preview_Checkbox' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/checkbox.php',
|
||||
'WPCF_Field_Renderer_Preview_Checkboxes' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/checkboxes.php',
|
||||
'WPCF_Field_Renderer_Preview_Colorpicker' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/colorpicker.php',
|
||||
'WPCF_Field_Renderer_Preview_Date' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/date.php',
|
||||
'WPCF_Field_Renderer_Preview_File' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/file.php',
|
||||
'WPCF_Field_Renderer_Preview_Image' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/image.php',
|
||||
'WPCF_Field_Renderer_Preview_Radio' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/radio.php',
|
||||
'WPCF_Field_Renderer_Preview_Skype' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/skype.php',
|
||||
'WPCF_Field_Renderer_Preview_Textfield' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/textfield.php',
|
||||
'WPCF_Field_Renderer_Preview_URL' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/preview/url.php',
|
||||
'WPCF_Field_Renderer_Toolset_Forms' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field/renderer/toolset_forms.php',
|
||||
'WPCF_Fields' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/fields.php',
|
||||
'WPCF_GUI_Term_Field_Editing' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/gui/term_field_editing.php',
|
||||
'WPCF_Helper_Ajax' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/helper.ajax.php',
|
||||
'WPCF_Import_Export' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/class.wpcf-import-export.php',
|
||||
'WPCF_Loader' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/loader.php',
|
||||
'WPCF_Page_Abstract' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/page/abstract.php',
|
||||
'WPCF_Page_Edit_Termmeta' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/page/edit/termmeta.php',
|
||||
'WPCF_Page_Edit_Termmeta_Form' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/page/edit/termmeta_form.php',
|
||||
'WPCF_Page_Listing_Abstract' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/page/listing/abstract.php',
|
||||
'WPCF_Page_Listing_Table' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/page/listing/table.php',
|
||||
'WPCF_Page_Listing_Termmeta' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/page/listing/termmeta.php',
|
||||
'WPCF_Page_Listing_Termmeta_Table' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/page/listing/termmeta_table.php',
|
||||
'WPCF_Path' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/path.php',
|
||||
'WPCF_Post_Types' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/class.wpcf-post-types.php',
|
||||
'WPCF_Relationship_Child_Form' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/relationship/form-child.php',
|
||||
'WPCF_Relationship' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/relationship.php',
|
||||
'WPCF_Repeater' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/repeater.php',
|
||||
'WPCF_Roles' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.wpcf.roles.php',
|
||||
'WPCF_Termmeta_Field' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/field.php',
|
||||
'WPCF_Termmeta_Repeater' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/repeater.php',
|
||||
'WPCF_Types_Marketing' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.wpcf.marketing.php',
|
||||
'WPCF_Types_Marketing_Messages' => dirname( __FILE__ ) . '/../vendor/toolset/types/includes/classes/class.wpcf.marketing.messages.php',
|
||||
'WPCF_Usermeta_Field' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/usermeta_field.php',
|
||||
'WPCF_Usermeta_Repeater' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/usermeta_repeater.php',
|
||||
'WPCF_Validation' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/validation.php',
|
||||
'WPCF_WPViews' => dirname( __FILE__ ) . '/../vendor/toolset/types/embedded/classes/wpviews.php',
|
||||
);
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Autoloader
|
||||
*/
|
||||
require_once( TYPES_ABSPATH . '/vendor/toolset/autoloader/autoloader.php' );
|
||||
|
||||
$autoloader = Toolset_Autoloader::get_instance();
|
||||
|
||||
$autoloader->add_path( 'Toolset', TYPES_ABSPATH . '/vendor/toolset' );
|
||||
|
||||
|
||||
/*
|
||||
* Load old Types
|
||||
*/
|
||||
if( ! defined( 'WPCF_RELPATH' ) ) {
|
||||
define( 'WPCF_RELPATH', TYPES_RELPATH . '/vendor/toolset/types' );
|
||||
}
|
||||
|
||||
if( ! defined( 'WPCF_EMBEDDED_TOOLSET_ABSPATH' ) ) {
|
||||
define( 'WPCF_EMBEDDED_TOOLSET_ABSPATH', TYPES_ABSPATH . '/vendor/toolset' );
|
||||
}
|
||||
|
||||
if( ! defined( 'WPCF_EMBEDDED_TOOLSET_RELPATH') ) {
|
||||
define( 'WPCF_EMBEDDED_TOOLSET_RELPATH', TYPES_RELPATH . '/vendor/toolset' );
|
||||
}
|
||||
|
||||
if( ! defined( 'WPTOOLSET_COMMON_PATH' ) ) {
|
||||
define( 'WPTOOLSET_COMMON_PATH', TYPES_ABSPATH . '/vendor/toolset/toolset-common' );
|
||||
}
|
||||
|
||||
if ( !defined( 'EDITOR_ADDON_RELPATH' ) ) {
|
||||
define( 'EDITOR_ADDON_RELPATH', WPCF_EMBEDDED_TOOLSET_RELPATH . '/toolset-common/visual-editor' );
|
||||
}
|
||||
|
||||
// installer
|
||||
$installer = TYPES_ABSPATH . '/vendor/otgs/installer/loader.php';
|
||||
if ( file_exists( $installer ) ) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include_once $installer;
|
||||
if ( function_exists( 'WP_Installer_Setup' ) ) {
|
||||
WP_Installer_Setup(
|
||||
$wp_installer_instance,
|
||||
array(
|
||||
'plugins_install_tab' => '1',
|
||||
'repositories_include' => array('toolset', 'wpml')
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get new functions.php
|
||||
require_once( dirname( __FILE__ ) . '/functions.php' );
|
||||
|
||||
// Initialize legacy code
|
||||
require_once( dirname( __FILE__ ) . '/../vendor/toolset/types/wpcf.php' );
|
||||
|
||||
// Public API
|
||||
require_once( dirname( __FILE__ ) . '/controllers/main.php' );
|
||||
|
||||
// Jumpstart new Types
|
||||
Types_Main::initialize();
|
||||
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Main backend controller for Types.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Admin {
|
||||
|
||||
|
||||
/**
|
||||
* Initialize Types for backend.
|
||||
*
|
||||
* This is expected to be called during init.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static function initialize() {
|
||||
new self();
|
||||
}
|
||||
|
||||
|
||||
private function __construct() {
|
||||
$this->on_init();
|
||||
}
|
||||
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
private function on_init() {
|
||||
|
||||
Types_Upgrade::initialize();
|
||||
|
||||
// Load Twig - this is a bit hacky way to do it, see Types_Twig_Autoloader class for explanation.
|
||||
Types_Twig_Autoloader::register();
|
||||
|
||||
// Load menu - won't be loaded in embedded version.
|
||||
if( apply_filters( 'types_register_pages', true ) ) {
|
||||
Types_Admin_Menu::initialize();
|
||||
}
|
||||
|
||||
$this->init_page_extensions();
|
||||
|
||||
// admin notices
|
||||
Toolset_Singleton_Factory::get( 'Types_Admin_Notices_Free_Version' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add hooks for loading page extensions.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
private function init_page_extensions() {
|
||||
// extensions for post edit page
|
||||
add_action( 'load-post.php', array( 'Types_Page_Extension_Edit_Post', 'get_instance' ) );
|
||||
|
||||
// extension for post type edit page
|
||||
add_action( 'load-toolset_page_wpcf-edit-type', array( 'Types_Page_Extension_Edit_Post_Type', 'get_instance' ) );
|
||||
|
||||
// extension for post fields edit page
|
||||
add_action( 'load-toolset_page_wpcf-edit', array( 'Types_Page_Extension_Edit_Post_Fields', 'get_instance' ) );
|
||||
|
||||
// settings
|
||||
add_action( 'load-toolset_page_toolset-settings', array( $this, 'init_settings' ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the extension for the Toolset Settings page.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public function init_settings() {
|
||||
$settings = new Types_Page_Extension_Settings();
|
||||
$settings->build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Admin menu controller for Types.
|
||||
*
|
||||
* All Types pages, menus, submenus and whatnot need to be registered here. One of the main goals is to avoid
|
||||
* loading specific page controllers unless their page is actually being loaded. All page slugs in Types *must*
|
||||
* be defined here as constants PAGE_NAME_*.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Admin_Menu {
|
||||
|
||||
/** Temporary slug compatible with the legacy code. */
|
||||
const MENU_SLUG = 'wpcf';
|
||||
|
||||
|
||||
// All (non-legacy) page slugs.
|
||||
const PAGE_NAME_FIELD_CONTROL = 'types-field-control';
|
||||
const PAGE_NAME_HELPER = 'types-helper'; // hidden page
|
||||
const PAGE_NAME_DASHBOARD = 'types-dashboard';
|
||||
|
||||
|
||||
private static $instance;
|
||||
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
public static function initialize() {
|
||||
self::get_instance();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function __construct() {
|
||||
// Priority is hardcoded by filter documentation.
|
||||
add_filter( 'toolset_filter_register_menu_pages', array( $this, 'on_admin_menu' ), 10 );
|
||||
|
||||
// Load Dashboard
|
||||
Types_Page_Dashboard::get_instance();
|
||||
}
|
||||
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
/**
|
||||
* Add all Types submenus and jumpstart a specific page controller if needed.
|
||||
*
|
||||
* Toolset shared menu usage is described here:
|
||||
* @link https://git.onthegosystems.com/toolset/toolset-common/wikis/toolset-shared-menu
|
||||
*
|
||||
* @param array $pages Array of menu item definitions.
|
||||
* @return array Updated item definition array.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function on_admin_menu( $pages ) {
|
||||
// Add legacy pages
|
||||
$pages = wpcf_admin_toolset_register_menu_pages( $pages );
|
||||
|
||||
$page_name = sanitize_text_field( wpcf_getget( 'page' ) );
|
||||
if( !empty( $page_name ) ) {
|
||||
$pages = $this->maybe_add_ondemand_submenu( $pages, $page_name );
|
||||
}
|
||||
return $pages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an on-demand submenu should be added, and jumpstart it's controller if needed.
|
||||
*
|
||||
* On-demand submenu means that the submenu isn't displayed normally, it appears only when its page is loaded.
|
||||
*
|
||||
* Note: All page controllers should inherit from Types_Page_Abstract.
|
||||
*
|
||||
* @param array $pages Array of menu item definitions.
|
||||
* @param string $page_name
|
||||
* @return array Updated item definition array.
|
||||
* @since 2.0
|
||||
*/
|
||||
private function maybe_add_ondemand_submenu( $pages, $page_name ) {
|
||||
$page = null;
|
||||
switch( $page_name ) {
|
||||
case self::PAGE_NAME_FIELD_CONTROL:
|
||||
$page = Types_Page_Field_Control::get_instance();
|
||||
break;
|
||||
case self::PAGE_NAME_HELPER:
|
||||
Types_Page_Hidden_Helper::get_instance();
|
||||
break;
|
||||
}
|
||||
|
||||
if( $page instanceof Types_Page_Abstract ) {
|
||||
|
||||
// Jumpstart the page controller.
|
||||
try {
|
||||
$page->prepare();
|
||||
} catch( Exception $e ) {
|
||||
wp_die( $e->getMessage() );
|
||||
}
|
||||
|
||||
$pages[ $page_name ] = array(
|
||||
'slug' => $page_name,
|
||||
'menu_title' => $page->get_title(),
|
||||
'page_title' => $page->get_title(),
|
||||
'callback' => $page->get_render_callback(),
|
||||
'load_hook' => $page->get_load_callback(),
|
||||
'capability' => $page->get_required_capability(),
|
||||
'contextual_help_hook' => array( Types_Asset_Help_Tab_Loader::get_instance(), 'add_help_tab' )
|
||||
);
|
||||
|
||||
// todo we might need to handle adding URL parameters to submenu URLs in some standard way, it's common scenario for ondemand submenus
|
||||
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Types_Admin_Notices_Free_Version
|
||||
*
|
||||
* Controls all admin notices which are only relevant for the free version of Types
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
class Types_Admin_Notices_Free_Version extends Toolset_Controller_Admin_Notices {
|
||||
|
||||
const NOTICE_TYPES_3_0 = 'types-3-0-features';
|
||||
const NOTICE_TYPES_3_1 = 'types-3-1-features';
|
||||
|
||||
/**
|
||||
* Types_Admin_Notices_Free_Version constructor.
|
||||
* (same as parent, but as we use $this to call the action it's important to overwrite it)
|
||||
*
|
||||
* @param Toolset_Constants|null $constants
|
||||
*/
|
||||
public function __construct( Toolset_Constants $constants = null ) {
|
||||
if ( null === $constants ) {
|
||||
$constants = new Toolset_Constants();
|
||||
}
|
||||
$this->constants = $constants;
|
||||
|
||||
add_action( 'init', array( $this, 'init' ), 1000 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init notices by screen
|
||||
*/
|
||||
public function init_screens() {
|
||||
if( ! function_exists( 'get_current_screen' ) ) {
|
||||
// loaded to early
|
||||
return;
|
||||
}
|
||||
|
||||
$this->current_screen = get_current_screen();
|
||||
|
||||
$this->screen_wordpress_dashboard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notices for the Wordpress Dashboard Page
|
||||
*/
|
||||
protected function screen_wordpress_dashboard() {
|
||||
if( $this->get_current_screen_id() != 'dashboard' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->new_features_of_paid_types();
|
||||
}
|
||||
|
||||
/**
|
||||
* New feature of paid types
|
||||
* Will only show notices if only types is active
|
||||
*/
|
||||
private function new_features_of_paid_types() {
|
||||
if( ! $this->only_types_active() ) {
|
||||
// not only types active
|
||||
return;
|
||||
}
|
||||
|
||||
// new features of paid types (here should only be the newest version,
|
||||
// otherwise new clients or old on new installations see all release notices)
|
||||
$this->notice_types_release_3_0();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice about Types 3.0 features
|
||||
*
|
||||
* @return bool|Toolset_Admin_Notice_Dismissible
|
||||
*/
|
||||
private function notice_types_release_3_0() {
|
||||
$notice = new Toolset_Admin_Notice_Dismissible( self::NOTICE_TYPES_3_0, '', $this->constants );
|
||||
$notice->set_similar_notices_key( Toolset_Admin_Notices_Manager::SIMILAR_NOTICES_FREE_PLUGIN_SHOWS_PAID_FEATURES );
|
||||
$notice->set_content( TYPES_ABSPATH . '/application/views/admin-notices/free-version/types-3-0.phtml' );
|
||||
Toolset_Admin_Notices_Manager::add_notice( $notice );
|
||||
|
||||
return $notice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice about Types 3.1 features
|
||||
*
|
||||
* NOT USED YET - ADDED FOR TESTING AND KEPT IT FOR NEXT RELEASE
|
||||
*
|
||||
* @return bool|Toolset_Admin_Notice_Dismissible
|
||||
*/
|
||||
private function notice_types_release_3_1() {
|
||||
$notice = new Toolset_Admin_Notice_Dismissible( self::NOTICE_TYPES_3_1, '', $this->constants );
|
||||
$notice->set_similar_notices_key( Toolset_Admin_Notices_Manager::SIMILAR_NOTICES_FREE_PLUGIN_SHOWS_PAID_FEATURES );
|
||||
$notice->set_content( TYPES_ABSPATH . '/application/views/admin-notices/free-version/types-3-1.phtml' );
|
||||
Toolset_Admin_Notices_Manager::add_notice( $notice );
|
||||
|
||||
return $notice;
|
||||
}
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class of helper functions that don't fit anywhere else.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
final class Types_Utils {
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut method for retrieving public built-in taxonomies.
|
||||
*
|
||||
* @param string $output_mode 'objects'|'names'
|
||||
*
|
||||
* @return object[] Array of taxonomy objects or names.
|
||||
* @since 1.9
|
||||
*/
|
||||
public static function get_builtin_taxonomies( $output_mode = 'objects' ) {
|
||||
// todo add simple caching
|
||||
return get_taxonomies( array( 'public' => true, '_builtin' => true ), $output_mode );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of taxonomies that should be excluded from any sort of Types/Toolset functionality.
|
||||
*
|
||||
* @return string[] Taxonomy slugs.
|
||||
* @since 2.2.9
|
||||
*/
|
||||
public static function get_excluded_taxonomies() {
|
||||
return array( 'nav_menu', 'link_category', 'post_format' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get registered taxonomies that can be edited by Types/Toolset.
|
||||
*
|
||||
* That includes custom taxonomies from Types and the built-in ones (which are not excluded).
|
||||
*
|
||||
* @return WP_Taxonomy[] Taxonomy objects.
|
||||
* @since 2.2.9
|
||||
*/
|
||||
public static function get_editable_taxonomies() {
|
||||
$custom_taxonomies = array_keys( wpcf_ensarr( get_option( WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array() ) ) );
|
||||
$builtin_taxonomies = self::get_builtin_taxonomies( 'names' );
|
||||
$allowed_taxonomies = array_merge( $custom_taxonomies, $builtin_taxonomies );
|
||||
|
||||
$excluded_taxonomies = self::get_excluded_taxonomies();
|
||||
$allowed_taxonomies = array_diff( $allowed_taxonomies, $excluded_taxonomies );
|
||||
|
||||
$taxonomies = get_taxonomies( '', 'objects' );
|
||||
foreach( $taxonomies as $taxonomy_slug => $taxonomy ) {
|
||||
if( ! in_array( $taxonomy_slug, $allowed_taxonomies ) ) {
|
||||
unset( $taxonomies[ $taxonomy_slug ] );
|
||||
}
|
||||
}
|
||||
|
||||
return $taxonomies;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a definitive set of all taxonomies recognized by Types.
|
||||
*
|
||||
* That also includes inactive taxonomies.
|
||||
* Respects if some builtin taxonomy is overridden by Types.
|
||||
*
|
||||
* @return array
|
||||
* @since 1.9
|
||||
*/
|
||||
public static function get_all_taxonomies() {
|
||||
// todo add simple caching
|
||||
$taxonomies = array();
|
||||
|
||||
// Read Types taxonomies first.
|
||||
$types_taxonomies = get_option( WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array() );
|
||||
if ( is_array( $types_taxonomies ) ) {
|
||||
foreach ( $types_taxonomies as $slug => $data ) {
|
||||
$taxonomies[ $slug ] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
// Get all taxonomies and add them to the set, but avoid overwriting Types taxonomies
|
||||
$all_taxonomies = self::object_to_array_deep( get_taxonomies( array( 'public' => true ) , 'objects' ) );
|
||||
foreach ( $all_taxonomies as $slug => $data ) {
|
||||
// check if taxonomies are already saved as custom taxonomies
|
||||
if ( isset( $taxonomies[ $slug ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! isset( $data['slug'] ) ) {
|
||||
$data['slug'] = $slug;
|
||||
}
|
||||
|
||||
$taxonomies[ $slug ] = $data;
|
||||
}
|
||||
|
||||
return $taxonomies;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transform an object and all it's fields recursively into an associative array. If any object's field is
|
||||
* an array, individual elements of the array will be transformed as well.
|
||||
*
|
||||
* @param object|array $object The object or array of objects to transform.
|
||||
* @return array
|
||||
* @since 1.9
|
||||
*/
|
||||
public static function object_to_array_deep( $object ) {
|
||||
if ( is_array( $object ) || is_object( $object ) ) {
|
||||
$result = array();
|
||||
foreach ( $object as $key => $value ) {
|
||||
$result[ $key ] = self::object_to_array_deep( $value );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to convert a taxonomy slug to a label.
|
||||
*
|
||||
* @param string $slug Taxonomy slug.
|
||||
* @param string $label_name One of the available labels of the taxonomy.
|
||||
*
|
||||
* @link https://codex.wordpress.org/Function_Reference/get_taxonomies Taxonomy object description.
|
||||
*
|
||||
* @return string Selected taxonomy label or slug if the label was not found.
|
||||
* @since 1.9
|
||||
*/
|
||||
public static function taxonomy_slug_to_label( $slug, $label_name = 'name' ) {
|
||||
$all_taxonomies = self::get_all_taxonomies();
|
||||
|
||||
$taxonomy_display_name = wpcf_getnest( $all_taxonomies, array( $slug, 'labels', $label_name ), $slug );
|
||||
|
||||
return $taxonomy_display_name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if searched string is a substring of the value.
|
||||
*
|
||||
* @param string $search_string
|
||||
* @param string $value
|
||||
* @return bool
|
||||
* @since 1.9
|
||||
*/
|
||||
public static function is_string_match( $search_string, $value ) {
|
||||
return ( false !== strpos( mb_strtolower( $value ), mb_strtolower( trim( $search_string ) ) ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert elements into source array at a specified position.
|
||||
*
|
||||
* @param array $source Source array.
|
||||
* @param array $to_insert Array of elements to insert.
|
||||
* @param int|array $position When integer is provided, zero or positive value means index of the first element that
|
||||
* will not be included before $to_insert. Negative value defines the position from the end of the source array
|
||||
* (-1 will insert at the very end, -2 before last element, etc.). When an array is provided, it is expected to
|
||||
* have form:
|
||||
* - 'key': Key to select an element in the source array
|
||||
* - 'where': Insert 'before'|'after' the selected element
|
||||
*
|
||||
* @return array
|
||||
* @since 1.9.1
|
||||
*/
|
||||
public static function insert_at_position( $source, $to_insert, $position) {
|
||||
|
||||
if( is_array( $position ) ) {
|
||||
$pivot_key = wpcf_getarr( $position, 'key', null );
|
||||
$direction = wpcf_getarr( $position, 'where', 'after', array( 'after', 'before' ) );
|
||||
|
||||
if( array_key_exists( $pivot_key, $source ) ) {
|
||||
$pivot_index = array_search( $pivot_key, array_keys( $source ) );
|
||||
$position = ( 'before' == $direction ) ? $pivot_index : $pivot_index + 1;
|
||||
} else {
|
||||
$position = ( 'before' == $direction ) ? 0 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
// $position should be index of the first element that will NOT be included before $to_insert.
|
||||
$position = (int) $position;
|
||||
|
||||
if( 0 > $position ) {
|
||||
// E.g.: When $position == -1, the inserted elements should be placed after the last element of $source.
|
||||
// $position will point after the last element of $source, new elements will be inserted after it.
|
||||
$position = count( $source ) + 1 + $position;
|
||||
//echo "pos=$position\n";
|
||||
|
||||
// Handle too low $position value - insert elements before whole $source.
|
||||
if( 0 > $position ) {
|
||||
$position = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$first_source_part = array_slice( $source, 0, $position );
|
||||
$second_source_part = array_slice( $source, $position );
|
||||
$result = array_merge( $first_source_part, $to_insert, $second_source_part );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return an ID of an attachment by searching the database with the file URL.
|
||||
*
|
||||
* First checks to see if the $url is pointing to a file that exists in
|
||||
* the wp-content directory. If so, then we search the database for a
|
||||
* partial match consisting of the remaining path AFTER the wp-content
|
||||
* directory. Finally, if a match is found the attachment ID will be
|
||||
* returned.
|
||||
*
|
||||
* Taken from:
|
||||
* @link http://frankiejarrett.com/get-an-attachment-id-by-url-in-wordpress/
|
||||
*
|
||||
* @param string $url URL of the file.
|
||||
* @return int|null Attachment ID if it exists.
|
||||
* @since 1.9.1
|
||||
* @deprecated Since 2.2.7. Use Toolset_Utils::get_attachment_id_by_url() instead. To be removed in 2.3 or later.
|
||||
*/
|
||||
public static function get_attachment_id_by_url( $url ) {
|
||||
|
||||
// Split the $url into two parts with the wp-content directory as the separator.
|
||||
$parsed_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
|
||||
|
||||
// Return null if image is not on domain (WP_CONTENT_URL).
|
||||
if ( count( $parsed_url ) === 1 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the host of the current site and the host of the $url, ignoring www.
|
||||
$this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
|
||||
$file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
|
||||
|
||||
// Return nothing if there aren't any $url parts or if the current host and $url host do not match.
|
||||
$attachment_path = $parsed_url[1];
|
||||
if ( ! isset( $attachment_path ) || empty( $attachment_path ) || ( $this_host != $file_host ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Now we're going to quickly search the DB for any attachment GUID with a partial path match.
|
||||
// Example: /uploads/2013/05/test-image.jpg
|
||||
global $wpdb;
|
||||
|
||||
$query = $wpdb->prepare(
|
||||
"SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND guid LIKE %s",
|
||||
'%' . $attachment_path
|
||||
);
|
||||
|
||||
$attachment = $wpdb->get_col( $query );
|
||||
|
||||
if ( is_array( $attachment ) && ! empty( $attachment ) ) {
|
||||
return array_shift( $attachment );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Main AJAX call controller for Types.
|
||||
*
|
||||
* This class can be used in any way only after the Common Library is loaded.
|
||||
*
|
||||
* Please read the important usage instructions for the superclass:
|
||||
*
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Ajax extends Toolset_Ajax {
|
||||
const HANDLER_CLASS_PREFIX = 'Types_Ajax_Handler_';
|
||||
|
||||
// Action names
|
||||
const CALLBACK_FIELD_CONTROL_ACTION = 'field_control_action';
|
||||
const CALLBACK_CHECK_SLUG_CONFLICTS = 'check_slug_conflicts';
|
||||
const CALLBACK_SETTINGS_ACTION = 'settings_action';
|
||||
const CALLBACK_M2M_MIGRATION_PREVIEW_RELATIONSHIPS = 'm2m_migration_preview_relationships';
|
||||
const CALLBACK_M2M_MIGRATION_PREVIEW_ASSOCIATIONS = 'm2m_migration_preview_associations';
|
||||
const CALLBACK_CUSTOM_FIELDS_ACTION = 'custom_fields_action';
|
||||
const CALLBACK_RELATIONSHIPS_ACTION = 'relationships_action';
|
||||
const CALLBACK_RELATED_CONTENT_ACTION = 'related_content_action';
|
||||
const CALLBACK_FIELD_GROUP_EDIT_ACTION = 'field_group_edit_action';
|
||||
const CALLBACK_REPEATABLE_GROUP = 'repeatable_group';
|
||||
const CALLBACK_POST_REFERENCE_FIELD = 'post_reference_field';
|
||||
|
||||
|
||||
private static $callbacks = array(
|
||||
self::CALLBACK_FIELD_CONTROL_ACTION,
|
||||
self::CALLBACK_CHECK_SLUG_CONFLICTS,
|
||||
self::CALLBACK_SETTINGS_ACTION,
|
||||
self::CALLBACK_M2M_MIGRATION_PREVIEW_RELATIONSHIPS,
|
||||
self::CALLBACK_M2M_MIGRATION_PREVIEW_ASSOCIATIONS,
|
||||
self::CALLBACK_CUSTOM_FIELDS_ACTION,
|
||||
self::CALLBACK_RELATIONSHIPS_ACTION,
|
||||
self::CALLBACK_RELATED_CONTENT_ACTION,
|
||||
self::CALLBACK_FIELD_GROUP_EDIT_ACTION,
|
||||
self::CALLBACK_REPEATABLE_GROUP,
|
||||
self::CALLBACK_POST_REFERENCE_FIELD,
|
||||
);
|
||||
|
||||
|
||||
private static $types_instance;
|
||||
|
||||
|
||||
public static function get_instance() {
|
||||
if( null === self::$types_instance ) {
|
||||
self::$types_instance = new self();
|
||||
}
|
||||
return self::$types_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @param bool $capitalized
|
||||
* @return string
|
||||
* @since m2m
|
||||
*/
|
||||
protected function get_plugin_slug( $capitalized = false ) {
|
||||
return ( $capitalized ? 'Types' : 'types' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return array
|
||||
* @since m2m
|
||||
*/
|
||||
protected function get_callback_names() {
|
||||
return self::$callbacks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles all initialization of everything except AJAX callbacks itself that is needed when
|
||||
* we're DOING_AJAX.
|
||||
*
|
||||
* Since this is executed on every AJAX call, make sure it's as lightweight as possible.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function additional_ajax_init() {
|
||||
|
||||
// On the Add Term page, we need to initialize the page controller WPCF_GUI_Term_Field_Editing
|
||||
// so that it saves term fields (if there are any).
|
||||
add_action( 'create_term', array( $this, 'prepare_for_term_creation' ) );
|
||||
|
||||
add_action( 'updated_user_meta', array( $this, 'capture_columnshidden_update' ), 10, 4 );
|
||||
|
||||
// Handle partially refactored AJAX callbacks coming from wpcf_ajax_embedded()
|
||||
// or from wpcf_ajax(). The wp_ajax_wpcf_ajax action will be reached only if the $fallthrough variables
|
||||
// in those functions are set to true (which means that the call was not handled).
|
||||
add_action( 'wp_ajax_wpcf_ajax', array( $this, 'do_legacy_wpcf_ajax' ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* On the Add Term page, we need to initialize the page controller WPCF_GUI_Term_Field_Editing
|
||||
* so that it saves term fields (if there are any).
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public function prepare_for_term_creation() {
|
||||
|
||||
// Takes care of the rest, mainly we're interested about the create_{$taxonomy} action which follows
|
||||
// immediately after create_term.
|
||||
//
|
||||
// On actions fired on the Add Term page, the action POST variable is allways add-tag and the screen is set
|
||||
// to edit-{$taxonomy}. When creating the term on the post edit page, for example, the screen is not set. We use
|
||||
// this to further limit the resource wasting. However, initializing the controller even if it's not supposed to
|
||||
// will not lead to any errors - it gives up gracefully.
|
||||
$action = toolset_getpost( 'action' );
|
||||
$screen = toolset_getpost( 'screen', null );
|
||||
if( 'add-tag' == $action && null !== $screen ) {
|
||||
WPCF_GUI_Term_Field_Editing::initialize();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When updating screen options with hidden listing columns, we may need to store additional data.
|
||||
*
|
||||
* See WPCF_GUI_Term_Field_Editing::maybe_disable_column_autohiding() for details.
|
||||
*
|
||||
* @param mixed $meta_id Ignored.
|
||||
* @param mixed $object_id Ignored.
|
||||
* @param string $meta_key Meta key.
|
||||
* @param mixed $_meta_value Meta value. We expect it to be an array.
|
||||
* @since 2.1
|
||||
*/
|
||||
public function capture_columnshidden_update(
|
||||
/** @noinspection PhpUnusedParameterInspection */ $meta_id, $object_id, $meta_key, $_meta_value )
|
||||
{
|
||||
// We're looking for a meta_key that looks like "manage{$page_name}columnshidden".
|
||||
$txt_columnshidden = 'columnshidden';
|
||||
$is_columnshidden_option = ( 0 == strcmp( $txt_columnshidden, substr( $meta_key, strlen( $txt_columnshidden ) * -1 ) ) );
|
||||
|
||||
if( $is_columnshidden_option ) {
|
||||
|
||||
// Extract the page name from the meta_key
|
||||
$strip_begin = strlen( 'manage' );
|
||||
$strip_end = strlen( $txt_columnshidden );
|
||||
$page_name = substr( $meta_key, $strip_begin, strlen( $meta_key ) - ( $strip_begin + $strip_end ) );
|
||||
|
||||
// Determine if we're editing a taxonomy
|
||||
$txt_edit = 'edit-';
|
||||
$txt_edit_len = strlen( $txt_edit );
|
||||
$is_tax_edit_page = ( 0 == strcmp( $txt_edit, substr( $page_name, 0, $txt_edit_len ) ) );
|
||||
|
||||
// This is not 100% certain but attempting to handle a taxonomy that doesn't exist does no harm.
|
||||
if( $is_tax_edit_page ) {
|
||||
|
||||
// Now we know that we need to perform the extra action.
|
||||
$taxonomy_name = substr( $page_name, $txt_edit_len );
|
||||
$edit_term_page_extension = WPCF_GUI_Term_Field_Editing::get_instance();
|
||||
$edit_term_page_extension->maybe_disable_column_autohiding( $taxonomy_name, $_meta_value, $page_name );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This offers a possibility to handle legacy AJAX wp_ajax_wpcf_ajax calls
|
||||
* if they're not handled in the legacy code anymore.
|
||||
*
|
||||
* Note that the method needs to always finish with die() to keep consistency with the legacy code.
|
||||
*
|
||||
* @since 2.2.16
|
||||
*/
|
||||
public function do_legacy_wpcf_ajax() {
|
||||
die();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Abstract AJAX call handler.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
abstract class Types_Ajax_Handler_Abstract implements Types_Ajax_Handler_Interface {
|
||||
|
||||
|
||||
/** @var Types_Ajax */
|
||||
private $ajax_manager;
|
||||
|
||||
|
||||
/**
|
||||
* Types_Ajax_Handler_Abstract constructor.
|
||||
*
|
||||
* @param Types_Ajax $ajax_manager
|
||||
* @since 2.1
|
||||
*/
|
||||
public function __construct( $ajax_manager ) {
|
||||
$this->ajax_manager = $ajax_manager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Types AJAX manager.
|
||||
*
|
||||
* @return Types_Ajax
|
||||
*/
|
||||
protected function get_am() {
|
||||
return $this->ajax_manager;
|
||||
}
|
||||
|
||||
|
||||
protected function ajax_begin( $arguments ) {
|
||||
$am = $this->get_am();
|
||||
return $am->ajax_begin( $arguments );
|
||||
}
|
||||
|
||||
|
||||
protected function ajax_finish( $response, $is_success = true ) {
|
||||
$am = $this->get_am();
|
||||
return $am->ajax_finish( $response, $is_success );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,259 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handle checking for slug conflicts among different domains.
|
||||
*
|
||||
* Used by the slug_conflict_checker.js script. Compares given value with all values within specified domains
|
||||
* and reports if a conflict is found.
|
||||
*
|
||||
* Currently supported domains are:
|
||||
* - Post type rewrite slugs (value of the slug used for permalink rewriting or the post type slug if rewriting is
|
||||
* not enabled for that post type)
|
||||
* - Taxonomy rewrite slugs (analogous to post types)
|
||||
*
|
||||
*/
|
||||
class Types_Ajax_Handler_Check_Slug_Conflicts extends Types_Ajax_Handler_Abstract {
|
||||
|
||||
// Definition of supported domains
|
||||
const DOMAIN_POST_TYPE_REWRITE_SLUGS = 'post_type_rewrite_slugs';
|
||||
const DOMAIN_TAXONOMY_REWRITE_SLUGS = 'taxonomy_rewrite_slugs';
|
||||
|
||||
private static $supported_domains = array(
|
||||
self::DOMAIN_POST_TYPE_REWRITE_SLUGS,
|
||||
self::DOMAIN_TAXONOMY_REWRITE_SLUGS
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* todo document
|
||||
* @param array $arguments Original action arguments.
|
||||
* @return void
|
||||
*/
|
||||
function process_call( $arguments ) {
|
||||
|
||||
$this->ajax_begin(
|
||||
array( 'nonce' => Types_Ajax::CALLBACK_CHECK_SLUG_CONFLICTS )
|
||||
);
|
||||
|
||||
// Read and validate input
|
||||
$domains = wpcf_getpost( 'domains' );
|
||||
$value = wpcf_getpost( 'value' );
|
||||
$exclude = wpcf_getpost( 'exclude' );
|
||||
$exclude_id = wpcf_getarr( $exclude, 'id', 0 );
|
||||
$exclude_domain = wpcf_getarr( $exclude, 'domain' );
|
||||
$diff_domains = array_diff( $domains, self::$supported_domains );
|
||||
|
||||
if( !is_array( $domains )
|
||||
|| !empty( $diff_domains )
|
||||
|| !is_string( $value )
|
||||
|| !is_array( $exclude )
|
||||
|| 0 === $exclude_id
|
||||
|| !in_array( $exclude_domain, self::$supported_domains )
|
||||
) {
|
||||
$this->ajax_finish( array(), false );
|
||||
}
|
||||
|
||||
|
||||
$conflict = $this->check_slug_conflicts( $value, $domains, $exclude_domain, $exclude_id );
|
||||
|
||||
|
||||
// Parse output (report a conflict if there is any)
|
||||
if( false === $conflict ) {
|
||||
$this->ajax_finish( array( 'isConflict' => false ), true );
|
||||
} else {
|
||||
|
||||
$message = sprintf(
|
||||
'<strong>%s</strong>: %s',
|
||||
__( 'Warning', 'wpcf' ),
|
||||
wpcf_getarr( $conflict, 'message' )
|
||||
);
|
||||
|
||||
$this->ajax_finish(
|
||||
array(
|
||||
'isConflict' => true,
|
||||
'displayMessage' => $message
|
||||
),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check given slug for conflicts across defined domains.
|
||||
*
|
||||
* @param string $value Value to check.
|
||||
* @param string[] $domains Array of valid domains
|
||||
* @param string $exclude_domain Domain of the excluded object.
|
||||
* @param string|int|null $exclude_id Id of the excluded object.
|
||||
*
|
||||
* @return array|bool Conflict information (an associative array with conflicting_id, message) or false when
|
||||
* there's no conflict.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
private function check_slug_conflicts( $value, $domains, $exclude_domain, $exclude_id ) {
|
||||
|
||||
foreach( $domains as $domain ) {
|
||||
$conflict = $this->check_slug_conflicts_in_domain( $value, $domain, ( $domain == $exclude_domain ) ? $exclude_id : null );
|
||||
if( false !== $conflict ) {
|
||||
return $conflict;
|
||||
}
|
||||
}
|
||||
|
||||
// No conflicts found
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check given slug for conflicts in one domain.
|
||||
*
|
||||
* @param string $value Value to check.
|
||||
* @param string $domain Domain name.
|
||||
* @param string|int|null $exclude_id ID of an object to exclude within this domain, or null if there is none.
|
||||
*
|
||||
* @return array|bool Conflict information (an associative array with conflicting_id, message) or false when
|
||||
* there's no conflict.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
private function check_slug_conflicts_in_domain( $value, $domain, $exclude_id = null ) {
|
||||
switch( $domain ) {
|
||||
case self::DOMAIN_POST_TYPE_REWRITE_SLUGS:
|
||||
return $this->check_slug_conflicts_in_post_type_rewrite_rules( $value, $exclude_id );
|
||||
case self::DOMAIN_TAXONOMY_REWRITE_SLUGS:
|
||||
return $this->check_slug_conflicts_in_taxonomy_rewrite_rules( $value, $exclude_id );
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a slug for conflict with slugs used for taxonomy permalink rewriting.
|
||||
*
|
||||
* @param string $value Value to check.
|
||||
* @param string $exclude_id Taxonomy slug to exclude from checking.
|
||||
*
|
||||
* @return array|bool Conflict information (an associative array with conflicting_id, message) or false when
|
||||
* there's no conflict.
|
||||
* @since 2.1
|
||||
*/
|
||||
private function check_slug_conflicts_in_taxonomy_rewrite_rules( $value, $exclude_id ) {
|
||||
|
||||
// Merge currently registered taxonomies (which might include some from other plugins) and
|
||||
// Types settings (which might include deactivated taxonomies).
|
||||
$taxonomy_settings = get_option( WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array() );
|
||||
if( !is_array( $taxonomy_settings ) ) {
|
||||
return false;
|
||||
}
|
||||
$taxonomy_settings = array_merge( $taxonomy_settings, get_taxonomies( array(), 'objects' ) );
|
||||
|
||||
foreach( $taxonomy_settings as $taxonomy ) {
|
||||
|
||||
// Read information from the taxonomy object or Types settings
|
||||
if( is_object( $taxonomy ) ) {
|
||||
$slug = $taxonomy->name;
|
||||
$rewrite_slug = wpcf_getarr( $taxonomy->rewrite, 'slug' );
|
||||
$is_permalink_rewriting_enabled = !empty( $rewrite_slug );
|
||||
} else {
|
||||
$slug = wpcf_getarr( $taxonomy, 'slug' );
|
||||
$is_permalink_rewriting_enabled = (bool) wpcf_getnest( $taxonomy, array( 'rewrite', 'enabled' ) );
|
||||
$rewrite_slug = wpcf_getnest( $taxonomy, array( 'rewrite', 'slug' ) );
|
||||
}
|
||||
|
||||
if( $slug == $exclude_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Detect if there is a conflict
|
||||
$is_custom_slug_used = !empty( $rewrite_slug );
|
||||
|
||||
if( $is_permalink_rewriting_enabled ) {
|
||||
$conflict_candidate = ( $is_custom_slug_used ? $rewrite_slug : $slug );
|
||||
|
||||
if( $conflict_candidate == $value ) {
|
||||
|
||||
$conflict = array(
|
||||
'conflicting_id' => $slug,
|
||||
'message' => sprintf(
|
||||
__( 'The same value is already used in permalink rewrite rules for the taxonomy "%s". Using it again can cause issues with permalinks.', 'wpcf' ),
|
||||
esc_html( $slug )
|
||||
)
|
||||
);
|
||||
|
||||
return $conflict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No conflicts found.
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check a slug for conflict with slugs used for post type permalink rewriting.
|
||||
*
|
||||
* @param string $value Value to check.
|
||||
* @param string $exclude_id Post type slug to exclude from checking.
|
||||
*
|
||||
* @return array|bool Conflict information (an associative array with conflicting_id, message) or false when
|
||||
* there's no conflict.
|
||||
* @since 2.1
|
||||
*/
|
||||
private function check_slug_conflicts_in_post_type_rewrite_rules( $value, $exclude_id ) {
|
||||
|
||||
// Merge currently registered post types (which might include some from other plugins) and
|
||||
// Types settings (which might include deactivated post types).
|
||||
$post_type_option = new Types_Utils_Post_Type_Option();
|
||||
$post_type_settings = $post_type_option->get_post_types();
|
||||
if( !is_array( $post_type_settings ) ) {
|
||||
return false;
|
||||
}
|
||||
$post_type_settings = array_merge( $post_type_settings, get_post_types( array(), 'objects' ) );
|
||||
|
||||
foreach( $post_type_settings as $post_type ) {
|
||||
|
||||
// Read information from the post type object or Types settings
|
||||
if( is_object( $post_type ) ) {
|
||||
$slug = $post_type->name;
|
||||
$is_permalink_rewriting_enabled = (bool) wpcf_getarr( $post_type->rewrite, 'enabled' );
|
||||
$rewrite_slug = wpcf_getarr( $post_type->rewrite, 'slug' );
|
||||
$is_custom_slug_used = !empty( $rewrite_slug );
|
||||
} else {
|
||||
$slug = wpcf_getarr( $post_type, 'slug' );
|
||||
$is_permalink_rewriting_enabled = (bool) wpcf_getnest( $post_type, array( 'rewrite', 'enabled' ) );
|
||||
$is_custom_slug_used = ( wpcf_getnest( $post_type, array( 'rewrite', 'custom' ) ) == 'custom' );
|
||||
$rewrite_slug = wpcf_getnest( $post_type, array( 'rewrite', 'slug' ) );
|
||||
}
|
||||
|
||||
if( $slug == $exclude_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( $is_permalink_rewriting_enabled ) {
|
||||
$conflict_candidate = ( $is_custom_slug_used ? $rewrite_slug : $slug );
|
||||
|
||||
if( $conflict_candidate == $value ) {
|
||||
|
||||
$conflict = array(
|
||||
'conflicting_id' => $slug,
|
||||
'message' => sprintf(
|
||||
__( 'The same value is already used in permalink rewrite rules for the custom post type "%s". Using it again can cause issues with permalinks.', 'wpcf' ),
|
||||
esc_html( $slug )
|
||||
)
|
||||
);
|
||||
|
||||
return $conflict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No conflicts found.
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,367 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handle action with field definitions on the Field Control page.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
final class Types_Ajax_Handler_Field_Control_Action extends Types_Ajax_Handler_Abstract {
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* todo document
|
||||
*
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function process_call( $arguments ) {
|
||||
|
||||
$am = $this->get_am();
|
||||
|
||||
$am->ajax_begin( array( 'nonce' => $am->get_action_js_name( Types_Ajax::CALLBACK_FIELD_CONTROL_ACTION ) ) );
|
||||
|
||||
// Read and validate input
|
||||
$field_action = sanitize_text_field( wpcf_getpost( 'field_action' ) );
|
||||
$fields = wpcf_getpost( 'fields' ); // array of values, will be sanitized when processed
|
||||
|
||||
$current_domain = wpcf_getpost( 'domain', null, Types_Field_Utils::get_domains() );
|
||||
if( null == $current_domain ) {
|
||||
$am->ajax_finish( array( 'message' => __( 'Wrong field domain.', 'wpcf' ) ), false );
|
||||
}
|
||||
|
||||
if( !is_array( $fields ) || empty( $fields ) ) {
|
||||
$am->ajax_finish( array( 'message' => __( 'No fields have been selected.', 'wpcf' ) ), false );
|
||||
}
|
||||
|
||||
// will be sanitized when/if used by the action-specific method
|
||||
$action_specific_data = wpcf_getpost( 'action_specific', array() );
|
||||
|
||||
// Process fields one by one
|
||||
$errors = array();
|
||||
$results = array();
|
||||
foreach( $fields as $field ) {
|
||||
|
||||
$result = $this->single_field_control_action( $field_action, $field, $current_domain, $action_specific_data );
|
||||
|
||||
if( is_array( $result ) ) {
|
||||
// Array of errors
|
||||
$errors = array_merge( $errors, $result );
|
||||
} else if( $result instanceof WP_Error ) {
|
||||
// Single error
|
||||
$errors[] = $result;
|
||||
} else if( false == $result ) {
|
||||
// This should not happen...!
|
||||
$errors[] = new WP_Error( 0, __( 'An unexpected error happened while processing the request.', 'wpcf' ) );
|
||||
} else {
|
||||
// Success
|
||||
|
||||
// Save the field definition model as a result if we got a whole definition
|
||||
if( $result instanceof WPCF_Field_Definition ) {
|
||||
$result = $result->to_json();
|
||||
}
|
||||
|
||||
$results[ wpcf_getarr( $field, 'slug' ) ] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
$data = array( 'results' => $results );
|
||||
$is_success = empty( $errors );
|
||||
|
||||
if( !$is_success ) {
|
||||
$error_messages = array();
|
||||
/** @var WP_Error $error */
|
||||
foreach( $errors as $error ) {
|
||||
$error_messages[] = $error->get_error_message();
|
||||
}
|
||||
$data['messages'] = $error_messages;
|
||||
}
|
||||
|
||||
$am->ajax_finish( $data, $is_success );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $action_name One of the allowed action names: 'manage_with_types'
|
||||
* @param array $field Field definition model passed from JS.
|
||||
* @param string $domain Field domain name.
|
||||
* @param mixed $action_specific_data
|
||||
* @return bool|mixed|null|WP_Error|WP_Error[]|WPCF_Field_Definition An error, array of errors, boolean indicating
|
||||
* success or a result value to be passed back to JS.
|
||||
* @since 2.0
|
||||
*/
|
||||
private function single_field_control_action( $action_name, $field, $domain, $action_specific_data ) {
|
||||
|
||||
$field_slug = sanitize_text_field( wpcf_getarr( $field, 'slug' ) );
|
||||
|
||||
switch ( $action_name ) {
|
||||
|
||||
case 'manage_with_types':
|
||||
return $this->start_managing_field( sanitize_text_field( wpcf_getarr( $field, 'metaKey' ) ), $domain );
|
||||
|
||||
case 'stop_managing_with_types':
|
||||
return $this->stop_managing_field( $field_slug, $domain );
|
||||
|
||||
case 'change_group_assignment':
|
||||
// $action_specific_data is a list of group slugs, will be sanitized by
|
||||
// trying to load a group model
|
||||
return $this->change_assignment_to_groups( $field_slug, $domain, $action_specific_data );
|
||||
|
||||
case 'delete_field':
|
||||
return $this->delete_field( $field_slug, $domain );
|
||||
|
||||
case 'change_field_type':
|
||||
return $this->change_field_type( $field_slug, $domain, $action_specific_data );
|
||||
|
||||
case 'change_field_cardinality':
|
||||
return $this->change_field_cardinality( $field_slug, $domain, $action_specific_data );
|
||||
|
||||
default:
|
||||
return new WP_Error( 42, __( 'Invalid action name.', 'wpcf' ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Start managing a field with given meta_key with Types.
|
||||
*
|
||||
* Looks if there already exists a field definition that uses the meta_key. If yes, it's most probably a "disabled"
|
||||
* one, that is stored only for the possibility of later "re-activation" (which is happening now). In that case,
|
||||
* the field definition will be simply updated.
|
||||
*
|
||||
* If there is no matching field definition whatsoever, it will be created with in some default manner.
|
||||
* Check WPCF_Field_Definition_Factory::create_field_definition_for_existing_fields() for details.
|
||||
*
|
||||
* AJAX callback helper only, do not use elsewhere.
|
||||
*
|
||||
* @param string $meta_key
|
||||
* @param string $domain Field domain
|
||||
* @return false|null|WPCF_Field_Definition The updated/newly created field definition or falsy value on failure.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function start_managing_field( $meta_key, $domain ) {
|
||||
$factory = WPCF_Field_Definition_Factory::get_factory_by_domain( $domain );
|
||||
$definition = $factory->meta_key_belongs_to_types_field( $meta_key, 'definition' );
|
||||
if( null == $definition ) {
|
||||
$result = $factory->create_field_definition_for_existing_fields( $meta_key );
|
||||
if( false != $result ) {
|
||||
return $factory->load_field_definition( $result );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$is_success = $definition->set_types_management_status( true );
|
||||
return ( $is_success ? $definition : false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stop managing a field with given field slug by Types.
|
||||
*
|
||||
* AJAX callback helper only, do not use elsewhere.
|
||||
*
|
||||
* @param string $field_slug
|
||||
* @param string $domain Field domain.
|
||||
* @return WP_Error|WPCF_Field_Definition Error with a user-friendly message on failure
|
||||
* or the updated definition on success.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static function stop_managing_field( $field_slug, $domain ) {
|
||||
|
||||
$factory = WPCF_Field_Definition_Factory::get_factory_by_domain( $domain );
|
||||
$definition = $factory->load_field_definition( $field_slug );
|
||||
|
||||
if( null == $definition ) {
|
||||
|
||||
return new WP_Error( 42, sprintf( __( 'Field definition for field "%s" not found in options.', 'wpcf' ), sanitize_text_field( $field_slug ) ) );
|
||||
|
||||
} else {
|
||||
|
||||
$is_success = $definition->set_types_management_status( false );
|
||||
|
||||
if( $is_success ) {
|
||||
return $definition;
|
||||
} else {
|
||||
return new WP_Error(
|
||||
42,
|
||||
sprintf(
|
||||
__( 'Unable to set types management status for field definition "%s".', 'wpcf' ),
|
||||
sanitize_text_field( $field_slug )
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change which groups is a field definition associated with.
|
||||
*
|
||||
* AJAX callback helper only, do not use elsewhere.
|
||||
*
|
||||
* @param string $field_slug Field definition slug.
|
||||
* @param string $domain Field domain
|
||||
* @param string[][] $groups Action-specific data passed through AJAX. Array containing a single key 'group_slugs',
|
||||
* containing an array of field group slugs.
|
||||
*
|
||||
* @return WP_Error|WPCF_Field_Definition The updated field definition on success or an error object.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function change_assignment_to_groups( $field_slug, $domain, $groups ) {
|
||||
$factory = WPCF_Field_Definition_Factory::get_factory_by_domain( $domain );
|
||||
$definition = $factory->load_field_definition( $field_slug );
|
||||
if( null == $definition ) {
|
||||
return new WP_Error( 42, sprintf( __( 'Field definition for field "%s" not found in options.', 'wpcf' ), sanitize_text_field( $field_slug ) ) );
|
||||
}
|
||||
$new_groups = wpcf_ensarr( wpcf_getarr( $groups, 'group_slugs' ) );
|
||||
$associated_groups = $definition->get_associated_groups();
|
||||
$is_success = true;
|
||||
foreach( $associated_groups as $group ) {
|
||||
if( !in_array( $group->get_slug(), $new_groups ) ) {
|
||||
$is_success = $is_success && $group->remove_field_definition( $definition );
|
||||
}
|
||||
}
|
||||
$group_factory = $factory->get_group_factory();
|
||||
foreach( $new_groups as $new_group_slug ) {
|
||||
$new_group = $group_factory->load_field_group( $new_group_slug );
|
||||
if( null != $new_group ) {
|
||||
$is_success = $is_success && $new_group->add_field_definition( $definition );
|
||||
} else {
|
||||
$is_success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if( $is_success ) {
|
||||
return $definition;
|
||||
} else {
|
||||
return new WP_Error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a field definition and all values of the field within given domain.
|
||||
*
|
||||
* @param string $field_slug
|
||||
* @param string $domain
|
||||
* @return bool|WP_Error True for success, false or WP_Error on error.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function delete_field( $field_slug, $domain ) {
|
||||
|
||||
$factory = WPCF_Field_Definition_Factory::get_factory_by_domain( $domain );
|
||||
$definition = $factory->load_field_definition( $field_slug );
|
||||
if( null == $definition ) {
|
||||
return new WP_Error( 42, sprintf( __( 'Field definition for field "%s" not found in options.', 'wpcf' ), sanitize_text_field( $field_slug ) ) );
|
||||
} else if( ! $definition->is_managed_by_types() ) {
|
||||
return new WP_Error( 42, sprintf( __( 'Field "%s" will not be deleted because it is not managed by Types.', 'wpcf' ), sanitize_text_field( $field_slug ) ) );
|
||||
}
|
||||
|
||||
$response = $factory->delete_definition( $definition );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change a field type for given field definition.
|
||||
*
|
||||
* Performs checks if the conversion is allowed, and if not, generate a proper error message.
|
||||
*
|
||||
* @param string $field_slug
|
||||
* @param string $domain
|
||||
* @param string[] $arguments Needs to contain the 'field_type' key with target type slug.
|
||||
* @return false|WP_Error|WPCF_Field_Definition The updated definition on succes, error/false otherwise.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function change_field_type( $field_slug, $domain, $arguments ) {
|
||||
|
||||
// Load all information we need, fail if it doesn't exist.
|
||||
$factory = WPCF_Field_Definition_Factory::get_factory_by_domain( $domain );
|
||||
$definition = $factory->load_field_definition( $field_slug );
|
||||
if( null == $definition ) {
|
||||
return new WP_Error( 42, sprintf( __( 'Field definition for field "%s" not found in options.', 'wpcf' ), sanitize_text_field( $field_slug ) ) );
|
||||
} else if( ! $definition->is_managed_by_types() ) {
|
||||
return new WP_Error( 42, sprintf( __( 'Field "%s" will not be converted because it is not managed by Types.', 'wpcf' ), sanitize_text_field( $field_slug ) ) );
|
||||
}
|
||||
|
||||
$type_slug = sanitize_text_field( wpcf_getarr( $arguments, 'field_type' ) );
|
||||
$target_type = Types_Field_Type_Definition_Factory::get_instance()->load_field_type_definition( $type_slug );
|
||||
if( null == $target_type ) {
|
||||
return new WP_Error( 42, sprintf( __( 'Unknown field type "%s".', 'wpcf' ), $type_slug ) );
|
||||
}
|
||||
|
||||
// Check if we can convert between types
|
||||
$is_conversion_possible = Types_Field_Type_Converter::get_instance()->is_conversion_possible( $definition->get_type(), $target_type );
|
||||
if( !$is_conversion_possible ) {
|
||||
return new WP_Error(
|
||||
42,
|
||||
sprintf(
|
||||
__( 'Conversion from type "%s" to "%s" is currently not allowed.', 'wpcf' ),
|
||||
$definition->get_type()->get_display_name(),
|
||||
$target_type->get_display_name()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Check if we can do the conversion with current field's cardinality
|
||||
$is_cardinality_sustainable = ( ! $definition->get_is_repetitive() || $target_type->can_be_repetitive() );
|
||||
if( !$is_cardinality_sustainable ) {
|
||||
return new WP_Error(
|
||||
42,
|
||||
sprintf(
|
||||
__( 'Field "%s" cannot be converted from "%s" to "%s" because it is repetitive and the target type doesn\'t support that.', 'wpcf' ),
|
||||
$definition->get_display_name(),
|
||||
$definition->get_type()->get_display_name(),
|
||||
$target_type->get_display_name()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// All is fine, proceed.
|
||||
$result = $definition->change_type( $target_type );
|
||||
if( $result ) {
|
||||
return $definition;
|
||||
} else {
|
||||
// Something unexpected went wrong.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change cardinality of given field, if it is permitted by its type.
|
||||
*
|
||||
* @param string $field_slug Field definition slug.
|
||||
* @param string $domain Field domain.
|
||||
* @param string[] $arguments Needs to contain the 'target_cardinality' key with 'single'|'repetitive' value.
|
||||
* @return bool|WP_Error|WPCF_Field_Definition The updated definition on succes, error/false otherwise.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function change_field_cardinality( $field_slug, $domain, $arguments ) {
|
||||
$factory = WPCF_Field_Definition_Factory::get_factory_by_domain( $domain );
|
||||
$definition = $factory->load_field_definition( $field_slug );
|
||||
if( null == $definition ) {
|
||||
return new WP_Error( 42, sprintf( __( 'Field definition for field "%s" not found in options.', 'wpcf' ), sanitize_text_field( $field_slug ) ) );
|
||||
} else if( ! $definition->is_managed_by_types() ) {
|
||||
return new WP_Error( 42, sprintf( __( 'Field "%s" will not be converted because it is not managed by Types.', 'wpcf' ), sanitize_text_field( $field_slug ) ) );
|
||||
}
|
||||
|
||||
$target_cardinality = wpcf_getarr( $arguments, 'target_cardinality', null, array( 'single', 'repetitive' ) );
|
||||
if( null == $target_cardinality ) {
|
||||
return false;
|
||||
}
|
||||
$set_as_repetitive = ( 'repetitive' == $target_cardinality );
|
||||
|
||||
$result = $definition->set_is_repetitive( $set_as_repetitive );
|
||||
|
||||
if( $result ) {
|
||||
return $definition;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Save handler for types settings
|
||||
* Settings are defined in Controller/Page/Extension/Settings
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
final class Types_Ajax_Handler_Settings_Action extends Types_Ajax_Handler_Abstract {
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function process_call( $arguments ) {
|
||||
|
||||
$am = $this->get_am();
|
||||
|
||||
$am->ajax_begin( array( 'nonce' => $am->get_action_js_name( Types_Ajax::CALLBACK_SETTINGS_ACTION ) ) );
|
||||
|
||||
$setting = sanitize_text_field( wpcf_getpost( 'setting' ) );
|
||||
$setting_value = wpcf_getpost( 'setting_value' );
|
||||
|
||||
if( !is_array( $setting_value ) ) {
|
||||
parse_str( $setting_value, $setting_value );
|
||||
$setting_value = array_pop( $setting_value );
|
||||
}
|
||||
|
||||
$sanitized_value = array();
|
||||
foreach( $setting_value as $key => $value ) {
|
||||
$sanitized_key = sanitize_title( $key );
|
||||
$sanitized_value[ $sanitized_key ] = sanitize_text_field( $value );
|
||||
}
|
||||
|
||||
// use toolset settings if available
|
||||
if( class_exists( 'Toolset_Settings' )
|
||||
&& method_exists( 'Toolset_Settings', 'get_instance' ) ) {
|
||||
$toolset_settings = Toolset_Settings::get_instance();
|
||||
|
||||
if( method_exists( $toolset_settings, 'save' ) ) {
|
||||
$toolset_settings[ $setting ] = $sanitized_value;
|
||||
$toolset_settings->save();
|
||||
$am->ajax_finish( 'success', true );
|
||||
}
|
||||
} else {
|
||||
update_option( $setting, $sanitized_value );
|
||||
$am->ajax_finish( 'success', true );
|
||||
}
|
||||
|
||||
// default toolset setting error will be used
|
||||
// todo throw specific error
|
||||
$am->ajax_finish( array('error'), false );
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Interface for an AJAX call handler.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
interface Types_Ajax_Handler_Interface {
|
||||
|
||||
/**
|
||||
* Types_Ajax_Handler_Interface constructor.
|
||||
*
|
||||
* @param $ajax_manager Types_Ajax instance
|
||||
*/
|
||||
function __construct( $ajax_manager );
|
||||
|
||||
|
||||
/**
|
||||
* @param array $arguments Original action arguments.
|
||||
* @return void
|
||||
*/
|
||||
function process_call( $arguments );
|
||||
|
||||
}
|
||||
@@ -1,288 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Public Types hook API.
|
||||
*
|
||||
* This should be the only point where other plugins (incl. Toolset) interact with Types directly.
|
||||
* Always use as a singleton in production code.
|
||||
*
|
||||
* Note: Types_Api is initialized on after_setup_theme with priority 10.
|
||||
*
|
||||
* When implementing filter hooks, please follow these rules:
|
||||
*
|
||||
* 1. All filter names are automatically prefixed with 'types_'. Only lowercase characters and underscores
|
||||
* can be used.
|
||||
* 2. Filter names (without a prefix) should be defined in self::$callbacks.
|
||||
* 3. For each filter, there should be a dedicated class implementing the Types_Api_Handler_Interface. Name of the class
|
||||
* must be Types_Api_Handler_{$capitalized_filter_name}. So for example, for a hook to
|
||||
* 'types_import_from_zip_file' you need to create a class 'Types_Api_Handler_Import_From_Zip_File'.
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
final class Types_Api {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if ( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
public static function initialize() {
|
||||
$instance = self::get_instance();
|
||||
|
||||
$instance->register_callbacks();
|
||||
}
|
||||
|
||||
|
||||
/** Prefix for the callback method name */
|
||||
const CALLBACK_PREFIX = 'callback_';
|
||||
|
||||
/** Prefix for the handler class name */
|
||||
const HANDLER_CLASS_PREFIX = 'Types_Api_Handler_';
|
||||
|
||||
const DELIMITER = '_';
|
||||
|
||||
|
||||
private $callbacks_registered = false;
|
||||
|
||||
|
||||
/**
|
||||
* @var array Filter names (without prefix) as keys, filter parameters as values:
|
||||
* - int $args: Number of arguments of the filter
|
||||
*/
|
||||
private static $callbacks = array(
|
||||
|
||||
/**
|
||||
* types_import_from_zip_file
|
||||
*
|
||||
* Run an import operation from given ZIP file.
|
||||
*
|
||||
* The file will, unlike in normal Types import, NOT be deleted.
|
||||
*
|
||||
* The import will be performed in the context of Framework Installer Views demo, so everything existing
|
||||
* will be either overwritten or deleted.
|
||||
*
|
||||
* @param mixed $default Should be false/null value to indicate that the hook didn't run.
|
||||
* @param string $path Absolute path to the ZIP file with Types import data
|
||||
* @param array|null $args Optional array with arguments for the underlying legacy import routine.
|
||||
* @return true|WP_Error
|
||||
* @since 2.2
|
||||
*/
|
||||
'import_from_zip_file' => array( 'args' => 3 ),
|
||||
|
||||
|
||||
/**
|
||||
* types_query_groups
|
||||
*
|
||||
* Query field groups of one or more domains.
|
||||
*
|
||||
* @param mixed $ignored
|
||||
* @param array $query Field group query.
|
||||
* - 'domain': A single field domain (see Types_Field_Utils). Legacy domain names are also accepted:
|
||||
* 'posts'|'users'|'terms'|'postmeta'|'usermeta'|'termmeta'|'all'. For 'all',
|
||||
* the method returns a multidimensional arrays with results for individual domains:
|
||||
* array( 'posts' => array( ... ), 'users' => array( ... ), ... ).
|
||||
* - For the rest of the query arguments, see Types_Field_Group_Factory::query_groups().
|
||||
*
|
||||
* @return null|Types_Field_Group[] Groups, if any, or empty otherwise. Null is returned when the query
|
||||
* is invalid.
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
'query_groups' => array( 'args' => 2 ),
|
||||
|
||||
|
||||
/**
|
||||
* types_filter_get_field_group_ids_by_post_type
|
||||
*
|
||||
* Returns all ids of field groups assigned to the given post type.
|
||||
*
|
||||
* Note: This is used by CRED (auto complete form).
|
||||
*
|
||||
* @param mixed $ignored
|
||||
* @param string $post_type_slug
|
||||
*
|
||||
* @return array Post field group IDs (may come as numeric strings).
|
||||
*
|
||||
* @throws InvalidArgumentException when presented with a non-string post type.
|
||||
*
|
||||
* @since 2.2.14
|
||||
*/
|
||||
'filter_get_field_group_ids_by_post_type' => array( 'args' => 2 )
|
||||
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Add API filter hooks (if that wasn't done before).
|
||||
*
|
||||
* Reads self::$callbacks for hook definitions and adds older/special hooks.
|
||||
*/
|
||||
private function register_callbacks() {
|
||||
|
||||
if( $this->callbacks_registered ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach( self::$callbacks as $callback_name => $args ) {
|
||||
|
||||
$argument_count = wpcf_getarr( $args, 'args', 1 );
|
||||
|
||||
add_filter( 'types_' . $callback_name, array( $this, self::CALLBACK_PREFIX . $callback_name ), 10, $argument_count );
|
||||
}
|
||||
|
||||
$this->callbacks_registered = true;
|
||||
|
||||
/**
|
||||
* types_filter_query_field_definitions
|
||||
*
|
||||
* @param mixed $default
|
||||
* @param array $query Field definition query. See Types_Field_Definition_Factory::query() for allowed arguments.
|
||||
* Additionally, you can specify:
|
||||
* - 'domain': Field domain (see Types_Field_Utils; legacy domain names are also accepted):
|
||||
* 'posts'|'users'|'terms'|'postmeta'|'usermeta'|'termmeta'|'all'. For 'all',
|
||||
* the method returns a multidimensional arrays with results for individual domains:
|
||||
* array( 'posts' => array( ... ), 'users' => array( ... ), ... ).
|
||||
* @return null|array Field definition arrays, sanitized as per field type, or null if an error has occurred.
|
||||
* @since 2.1
|
||||
*/
|
||||
add_filter( 'types_filter_query_field_definitions', array( $this, 'query_field_definitions' ), 10, 2 );
|
||||
|
||||
|
||||
/**
|
||||
* types_is_active
|
||||
*
|
||||
* Indicate that Types is active. :-)
|
||||
*
|
||||
* @since 2.2
|
||||
* @return bool
|
||||
*/
|
||||
add_filter( 'types_is_active', '__return_true' );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle a call to undefined method on this class, hopefully an action/filter call.
|
||||
*
|
||||
* @param string $name Method name.
|
||||
* @param array $parameters Method parameters.
|
||||
* @since 2.1
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call( $name, $parameters ) {
|
||||
|
||||
$default_return_value = wpcf_getarr( $parameters, 0, null );
|
||||
|
||||
// Check for the callback prefix in the method name
|
||||
$name_parts = explode( self::DELIMITER, $name );
|
||||
if( 0 !== strcmp( $name_parts[0] . self::DELIMITER, self::CALLBACK_PREFIX ) ) {
|
||||
// Not a callback, resign.
|
||||
return $default_return_value;
|
||||
}
|
||||
|
||||
// Deduct the handler class name from the callback name
|
||||
unset( $name_parts[0] );
|
||||
$class_name = implode( self::DELIMITER, $name_parts );
|
||||
$class_name = strtolower( $class_name );
|
||||
$class_name = mb_convert_case( $class_name, MB_CASE_TITLE );
|
||||
$class_name = self::HANDLER_CLASS_PREFIX . $class_name;
|
||||
|
||||
// Obtain an instance of the handler class.
|
||||
try {
|
||||
/** @var Types_Api_Handler_Interface $handler */
|
||||
$handler = new $class_name();
|
||||
} catch( Exception $e ) {
|
||||
// The handler class could not have been instantiated, resign.
|
||||
return $default_return_value;
|
||||
}
|
||||
|
||||
// Success
|
||||
return $handler->process_call( $parameters );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Hook for types_filter_query_field_definitions.
|
||||
*
|
||||
* @param mixed $ignored
|
||||
* @param array $query Field definition query. See Types_Field_Definition_Factory::query() for supported arguments.
|
||||
* Additionally, you can specify:
|
||||
* - 'domain': A single field domain (see Types_Field_Utils) or 'all'. Legacy domain names are also accepted.
|
||||
* For 'all', the method returns a multidimensional arrays with results for individual domains:
|
||||
* - 'refresh': A boolean to refresh the definitions, useful when getting data after saving fields
|
||||
* array( 'posts' => array( ... ), 'users' => array( ... ), ... ).
|
||||
*
|
||||
* @note The 'refresh' parameter is temporal and might dissapear without prior notice when the groups and fields saving gets integrated in the fields definition factory
|
||||
*
|
||||
* @return null|array Field definition arrays, sanitized as per field type, or null if an error has occurred.
|
||||
* @since 2.1
|
||||
*/
|
||||
public function query_field_definitions(
|
||||
/** @noinspection PhpUnusedParameterInspection */ $ignored, $query
|
||||
) {
|
||||
$domain = wpcf_getarr( $query, 'domain', 'all' );
|
||||
|
||||
if( 'all' == $domain ) {
|
||||
|
||||
// Call itself for each available domain.
|
||||
$results_by_domain = array();
|
||||
$domains = Types_Field_Utils::get_domains();
|
||||
foreach( $domains as $field_domain ) {
|
||||
$per_domain_query = $query;
|
||||
$per_domain_query['domain'] = $field_domain;
|
||||
$results_by_domain[ $field_domain ] = $this->query_field_definitions( null, $per_domain_query );
|
||||
}
|
||||
|
||||
return $results_by_domain;
|
||||
|
||||
} else {
|
||||
|
||||
// Sanitize input
|
||||
if( ! is_string( $domain ) || ! is_array( $query ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the factory by domain, and if it fails, try to convert from legacy meta_type value.
|
||||
try {
|
||||
$definition_factory = Types_Field_Utils::get_definition_factory_by_domain( $domain );
|
||||
} catch( InvalidArgumentException $e ) {
|
||||
$definition_factory = null;
|
||||
}
|
||||
|
||||
if ( null == $definition_factory ) {
|
||||
try {
|
||||
$definition_factory = Types_Field_Utils::get_definition_factory_by_domain( Types_Field_Utils::legacy_meta_type_to_domain( $domain ) );
|
||||
} catch( InvalidArgumentException $e ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Allways query only Types fields.
|
||||
$query['filter'] = 'types';
|
||||
|
||||
if (
|
||||
isset( $query['refresh'] )
|
||||
&& $query['refresh']
|
||||
) {
|
||||
$definition_factory->clear_definition_storage();
|
||||
}
|
||||
|
||||
/** @var WPCF_Field_Definition[] $definitions */
|
||||
$definitions = $definition_factory->query_definitions( $query );
|
||||
$definition_arrays = array();
|
||||
foreach( $definitions as $definition ) {
|
||||
$definition_arrays[] = $definition->get_definition_array();
|
||||
}
|
||||
|
||||
return $definition_arrays;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handler for the types_filter_get_field_group_ids_by_post_type filter API.
|
||||
*
|
||||
* @since 2.2.14
|
||||
*/
|
||||
class Types_Api_Handler_Filter_Get_Field_Group_Ids_By_Post_Type implements Types_Api_Handler_Interface {
|
||||
|
||||
|
||||
private $wpdb;
|
||||
|
||||
|
||||
public function __construct( wpdb $wpdb_di = null ) {
|
||||
global $wpdb;
|
||||
$this->wpdb = ( null === $wpdb_di ? $wpdb : $wpdb_di );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $arguments Original action/filter arguments.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function process_call( $arguments ) {
|
||||
|
||||
$post_type = toolset_getarr( $arguments, 1 );
|
||||
|
||||
if( ! is_string( $post_type ) ) {
|
||||
throw new InvalidArgumentException( 'Invalid argument for a post type.' );
|
||||
}
|
||||
|
||||
$query = $this->wpdb->prepare(
|
||||
"SELECT post_id FROM {$this->wpdb->postmeta}
|
||||
WHERE
|
||||
meta_key = '_wp_types_group_post_types'
|
||||
AND (
|
||||
meta_value LIKE %s
|
||||
OR meta_value = 'all'
|
||||
OR meta_value REGEXP '^[,]+$'
|
||||
)
|
||||
ORDER BY post_id ASC",
|
||||
'%' . $post_type . '%'
|
||||
);
|
||||
|
||||
$post_ids = $this->wpdb->get_col( $query );
|
||||
|
||||
return $post_ids;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,141 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handler for the types_import_from_zip_file filter API.
|
||||
*
|
||||
* todo Handle results via Toolset_Result_Set.
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
class Types_Api_Handler_Import_From_Zip_File implements Types_Api_Handler_Interface {
|
||||
|
||||
|
||||
public function __construct() { }
|
||||
|
||||
|
||||
/**
|
||||
* @param array $arguments Original action/filter arguments.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function process_call( $arguments ) {
|
||||
|
||||
$path = wpcf_getarr( $arguments, 1, null );
|
||||
$args = wpcf_getarr( $arguments, 2, null );
|
||||
|
||||
if( ! is_string( $path ) || ! file_exists( $path ) ) {
|
||||
return new WP_Error( 42, __( 'Invalid path to the import file.', 'wpcf' ) );
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
$import_data = $this->get_data_from_file( $path );
|
||||
if( $import_data instanceof WP_Error ) {
|
||||
return $import_data;
|
||||
} elseif( null == $import_data ) {
|
||||
return new WP_Error( 42, __( 'The import file could not be processed, it seems to be corrupted.', 'wpcf' ) );
|
||||
}
|
||||
|
||||
$result = $this->hack_around_legacy_import_routine( $import_data, $args );
|
||||
|
||||
$message = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function hack_around_legacy_import_routine( $import_data, $import_args = null ) {
|
||||
|
||||
add_filter('wpcf_admin_message_store', '__return_false');
|
||||
|
||||
$_POST['overwrite-settings'] = isset( $import_args['overwrite-settings'] ) ? (bool) $import_args['overwrite-settings'] : false;
|
||||
|
||||
$_POST['overwrite-groups'] = (
|
||||
isset( $import_args['overwrite-groups'] ) && 1 == $import_args['overwrite-groups']
|
||||
? 1
|
||||
: 0
|
||||
);
|
||||
|
||||
$_POST['overwrite-fields'] = (
|
||||
isset( $import_args['overwrite-fields'] ) && 1 == $import_args['overwrite-fields']
|
||||
? 1
|
||||
: 0
|
||||
);
|
||||
|
||||
$_POST['overwrite-types'] = (
|
||||
isset( $import_args['overwrite-types'] ) && 1 == $import_args['overwrite-types']
|
||||
? 1
|
||||
: 0
|
||||
);
|
||||
|
||||
$_POST['overwrite-tax'] = (
|
||||
isset( $import_args['overwrite-tax'] ) && 1 == $import_args['overwrite-tax']
|
||||
? 1
|
||||
: 0
|
||||
);
|
||||
|
||||
$_POST['post_relationship'] = isset( $import_args['post_relationship'] ) ? (bool) $import_args['post_relationship'] : false;
|
||||
$_POST['delete-groups'] = isset( $import_args['delete-groups'] ) ? (bool) $import_args['delete-groups'] : false;
|
||||
$_POST['delete-fields'] = isset( $import_args['delete-fields'] ) ? (bool) $import_args['delete-fields'] : false;
|
||||
$_POST['delete-types'] = isset( $import_args['delete-types'] ) ? (bool) $import_args['delete-types'] : false;
|
||||
$_POST['delete-tax'] = isset( $import_args['delete-tax'] ) ? (bool) $import_args['delete-tax'] : false;
|
||||
|
||||
/**
|
||||
* This can be emtpy string '' or 'wpvdemo', but this second option has a serious bug with xml parsing/looping
|
||||
*/
|
||||
$context = isset( $import_args['context'] ) ? $import_args['context'] : '';
|
||||
// Not sure if this is needed
|
||||
require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
|
||||
require_once WPCF_EMBEDDED_INC_ABSPATH . '/import-export.php';
|
||||
|
||||
// Prepare legacy arguments for Types_Data_Installer
|
||||
$legacy_args = array();
|
||||
if ( isset($import_args['overwrite']) ){
|
||||
$legacy_args['force_import_post_name'] = wpcf_getarr( $import_args, 'overwrite', array() );
|
||||
}
|
||||
if ( isset($import_args['skip']) ){
|
||||
$legacy_args['force_skip_post_name'] = wpcf_getarr( $import_args, 'skip', array() );
|
||||
}
|
||||
if ( isset($import_args['duplicate']) ){
|
||||
$legacy_args['force_duplicate_post_name'] = wpcf_getarr( $import_args, 'duplicate', array() );
|
||||
}
|
||||
|
||||
$result = wpcf_admin_import_data( $import_data, false, $context, $legacy_args );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private function get_data_from_file( $path ) {
|
||||
|
||||
$info = pathinfo( $path );
|
||||
|
||||
$is_zip = $info['extension'] == 'zip' ? true : false;
|
||||
|
||||
$data = null;
|
||||
|
||||
if ( $is_zip ) {
|
||||
|
||||
$zip = zip_open( $path );
|
||||
|
||||
if ( is_resource( $zip ) ) {
|
||||
while( ( $zip_entry = zip_read( $zip ) ) !== false ) {
|
||||
if ( zip_entry_name( $zip_entry ) == 'settings.xml' ) {
|
||||
$data = @zip_entry_read( $zip_entry, zip_entry_filesize( $zip_entry ) );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return new WP_Error( 42, __( 'Unable to open zip file', 'wpcf' ) );
|
||||
}
|
||||
} else {
|
||||
// Not a zip file, we'll use it directly
|
||||
$data = @file_get_contents( $path );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Interface for handlers of hook API calls.
|
||||
*/
|
||||
interface Types_Api_Handler_Interface {
|
||||
|
||||
function __construct();
|
||||
|
||||
/**
|
||||
* @param array $arguments Original action/filter arguments.
|
||||
* @return mixed
|
||||
*/
|
||||
function process_call( $arguments );
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Handler for the types_query_groups filter.
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
class Types_Api_Handler_Query_Groups implements Types_Api_Handler_Interface {
|
||||
|
||||
|
||||
public function __construct() { }
|
||||
|
||||
|
||||
/**
|
||||
* @param array $arguments Original action/filter arguments.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function process_call( $arguments ) {
|
||||
|
||||
$query = wpcf_getarr( $arguments, 1, array() );
|
||||
|
||||
$domain = wpcf_getarr( $query, 'domain', 'all' );
|
||||
unset( $query['domain'] );
|
||||
|
||||
// Sanitize input
|
||||
if ( ! is_string( $domain ) || ! is_array( $query ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( 'all' == $domain ) {
|
||||
|
||||
// Separate query for each available domain.
|
||||
$groups_by_domain = array();
|
||||
$domains = Types_Field_Utils::get_domains();
|
||||
foreach( $domains as $field_domain ) {
|
||||
$groups_by_domain[ $field_domain ] = $this->query_specific_domain( $field_domain, $query );
|
||||
}
|
||||
|
||||
return $groups_by_domain;
|
||||
|
||||
} else {
|
||||
return $this->query_specific_domain( $domain, $query );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Query field groups from a single domain.
|
||||
*
|
||||
* @param string $domain One of the valid field domains. Legacy "meta type" values will be also accepted.
|
||||
* @param array $query Query arguments for Types_Field_Group_Factory::query_groups().
|
||||
*
|
||||
* @return null|Types_Field_Group[] Array of field groups or null on error.
|
||||
* @since m2m
|
||||
*/
|
||||
private function query_specific_domain( $domain, $query ) {
|
||||
|
||||
// Make sure we have a valid domain string.
|
||||
$valid_domains = Types_Field_Utils::get_domains();
|
||||
if( !in_array( $domain, $valid_domains ) ) {
|
||||
$domain = Types_Field_Utils::legacy_meta_type_to_domain( $domain );
|
||||
}
|
||||
|
||||
// Pass the group query to the proper factory class.
|
||||
try {
|
||||
$group_factory = Types_Field_Group_Factory::get_factory_by_domain( $domain );
|
||||
$groups = $group_factory->query_groups( $query );
|
||||
} catch( Exception $e ) {
|
||||
// We don't care, it's a failure.
|
||||
return null;
|
||||
}
|
||||
|
||||
return $groups;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Manages adding help tabs to admin pages.
|
||||
*
|
||||
* Usage: Set array( Types_Asset_Help_Tab_Loader::get_instance, 'add_help_tab' ) to 'contextual_help_hook' in
|
||||
* the shared Toolset menu item configuration and then extend the get_help_config() method to return a valid
|
||||
* help tab configuration for the needed page name.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Asset_Help_Tab_Loader {
|
||||
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() { }
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
/**
|
||||
* Add help tabs to current screen.
|
||||
*
|
||||
* Used as a hook for 'contextual_help_hook' in the shared Toolset menu.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function add_help_tab() {
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( is_null( $screen ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_page = sanitize_text_field( wpcf_getget( 'page', null ) );
|
||||
if ( null == $current_page ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$help_content = $this->get_help_content( $current_page );
|
||||
if( null == $help_content ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'title' => wpcf_getarr( $help_content, 'title' ),
|
||||
'id' => 'wpcf',
|
||||
'content' => wpcf_getarr( $help_content, 'content' ),
|
||||
'callback' => false,
|
||||
);
|
||||
|
||||
$screen->add_help_tab( $args );
|
||||
|
||||
$this->add_need_help_tab();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Need Help section for a bit advertising.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
private function add_need_help_tab() {
|
||||
|
||||
$args = array(
|
||||
'title' => __( 'Need More Help?', 'wpcf' ),
|
||||
'id' => 'custom_fields_group-need-help',
|
||||
'content' => wpcf_admin_help( 'need-more-help' ),
|
||||
'callback' => false,
|
||||
);
|
||||
|
||||
$screen = get_current_screen();
|
||||
$screen->add_help_tab( $args );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the configuration for help tab.
|
||||
*
|
||||
* The configuration needs to contain three keys:
|
||||
* - title: Title of the tab.
|
||||
* - template: Name of the Twig template (assuming the 'help' namespace is available)
|
||||
* - context: Context object for Twig.
|
||||
*
|
||||
* @param string $page_name Name of current page.
|
||||
* @return array|null Help tab configuration array or null when no help tab should be displayed.
|
||||
* @since 2.0
|
||||
*/
|
||||
private function get_help_config( $page_name ) {
|
||||
|
||||
switch( $page_name ) {
|
||||
case Types_Admin_Menu::PAGE_NAME_FIELD_CONTROL:
|
||||
return Types_Page_Field_Control::get_instance()->get_help_config();
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render help tab content from its configuration.
|
||||
*
|
||||
* @param string $page_name Name of current page.
|
||||
* @return array|null Null when no help tab should be displayed, or an array with keys 'title' and 'content'.
|
||||
* @since 2.0
|
||||
*/
|
||||
private function get_help_content( $page_name ) {
|
||||
|
||||
$config = $this->get_help_config( $page_name );
|
||||
if( null == $config ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$twig = $this->get_twig();
|
||||
|
||||
return array(
|
||||
'title' => wpcf_getarr( $config, 'title' ),
|
||||
'content' => $twig->render( wpcf_getarr( $config, 'template' ), wpcf_getarr( $config, 'context' ) )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/** @var Twig_Environment|null */
|
||||
private $twig = null;
|
||||
|
||||
|
||||
/**
|
||||
* @return Twig_Environment Initialized Twig environment object for help tab content rendering.
|
||||
* @throws Twig_Error_Loader
|
||||
* @since 2.0
|
||||
*/
|
||||
private function get_twig() {
|
||||
if( null == $this->twig ) {
|
||||
$loader = new Twig_Loader_Filesystem();
|
||||
$loader->addPath( TYPES_ABSPATH . '/application/views/help', 'help' );
|
||||
$this->twig = new Twig_Environment( $loader );
|
||||
}
|
||||
return $this->twig;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* The script and style asset manager for Types implemented in a standard Toolset way.
|
||||
*
|
||||
* Keeping this separate from Types_Assets also for performance reasons (this is not needed at all times).
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Asset_Manager extends Toolset_Assets_Manager {
|
||||
|
||||
// Script handles
|
||||
//
|
||||
// NEVER EVER use handles defined here as hardcoded strings, they may change at any time.
|
||||
|
||||
const SCRIPT_ADJUST_MENU_LINK = 'types-adjust-menu-link';
|
||||
const SCRIPT_SLUG_CONFLICT_CHECKER = 'types-slug-conflict-checker';
|
||||
|
||||
const SCRIPT_PAGE_EDIT_POST_TYPE = 'types-page-edit-post-type';
|
||||
const SCRIPT_PAGE_EDIT_TAXONOMY = 'types-page-edit-taxonomy';
|
||||
|
||||
// Registered in legacy Types
|
||||
|
||||
const SCRIPT_JQUERY_UI_VALIDATION = 'wpcf-form-validation';
|
||||
const SCRIPT_ADDITIONAL_VALIDATION_RULES = 'wpcf-form-validation-additional';
|
||||
|
||||
|
||||
|
||||
private static $types_instance;
|
||||
|
||||
|
||||
/**
|
||||
* @return Types_Asset_Manager
|
||||
*/
|
||||
static public function get_instance() {
|
||||
if( null === self::$types_instance ) {
|
||||
self::$types_instance = new self();
|
||||
}
|
||||
|
||||
return self::$types_instance;
|
||||
}
|
||||
|
||||
|
||||
protected function __initialize_styles() {
|
||||
return parent::__initialize_styles();
|
||||
}
|
||||
|
||||
|
||||
protected function __initialize_scripts() {
|
||||
|
||||
$this->register_script(
|
||||
self::SCRIPT_ADJUST_MENU_LINK,
|
||||
TYPES_RELPATH . '/public/page/adjust_submenu_links.js',
|
||||
array( 'jquery', 'underscore' ),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
$this->register_script(
|
||||
self::SCRIPT_SLUG_CONFLICT_CHECKER,
|
||||
TYPES_RELPATH . '/public/js/slug_conflict_checker.js',
|
||||
array( 'jquery', 'underscore' ),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
$this->register_script(
|
||||
self::SCRIPT_PAGE_EDIT_POST_TYPE,
|
||||
TYPES_RELPATH . '/public/page/edit_post_type/main.js',
|
||||
array( 'jquery', 'underscore', self::SCRIPT_SLUG_CONFLICT_CHECKER, self::SCRIPT_UTILS ),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
$this->register_script(
|
||||
self::SCRIPT_PAGE_EDIT_TAXONOMY,
|
||||
TYPES_RELPATH . '/public/page/edit_taxonomy/main.js',
|
||||
array( 'jquery', 'underscore', self::SCRIPT_SLUG_CONFLICT_CHECKER, self::SCRIPT_UTILS ),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
$this->register_script(
|
||||
self::SCRIPT_JQUERY_UI_VALIDATION,
|
||||
WPCF_RES_RELPATH . '/js/jquery-form-validation/' . $this->choose_script_version( 'jquery.validate.min.js', 'jquery.validate.js'),
|
||||
array( 'jquery' ),
|
||||
'1.8.1'
|
||||
);
|
||||
|
||||
|
||||
$this->register_script(
|
||||
self::SCRIPT_ADDITIONAL_VALIDATION_RULES,
|
||||
$this->get_additional_validation_script_url(),
|
||||
array( 'jquery', self::SCRIPT_JQUERY_UI_VALIDATION ),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
|
||||
return parent::__initialize_scripts();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unfortunately, we need to have this public because of the Divi.
|
||||
* And, unfortunately, we can't define it as a constant because PHP < 5.6 doesn't support that.
|
||||
*
|
||||
* @since 2.2.7
|
||||
*/
|
||||
public function get_additional_validation_script_url() {
|
||||
return WPCF_RES_RELPATH . '/js/jquery-form-validation/additional-methods.min.js';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Choose a production (usually minified) or debugging (non-minified) version of
|
||||
* a script depending on the script debugging mode.
|
||||
*
|
||||
* See SCRIPT_DEBUG constant
|
||||
*
|
||||
* @param string $production_version File name of the production script version.
|
||||
* @param string $debugging_version File name of the debugging script version.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.2.7
|
||||
*/
|
||||
private function choose_script_version( $production_version, $debugging_version ) {
|
||||
$is_debug_mode = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG );
|
||||
return ( $is_debug_mode ? $debugging_version : $production_version );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Toolset_Script $script
|
||||
*/
|
||||
public function register_toolset_script( $script ) {
|
||||
if ( ! isset( $this->scripts[ $script->handle ] ) ) {
|
||||
$this->scripts[ $script->handle ] = $script;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Toolset_Style $style
|
||||
*/
|
||||
public function register_toolset_style( $style ) {
|
||||
if( !isset( $this->styles[ $style->handle ] ) ) {
|
||||
$this->styles[ $style->handle ] = $style;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types assets manager.
|
||||
*
|
||||
* All assets (like images and other files) should be defined here, referenced only by constants and their paths/URLs
|
||||
* retrieved only with methods of this class.
|
||||
*
|
||||
* That will make their management way easier when some paths or filenames need to be changed.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Assets {
|
||||
|
||||
// Constants with image paths relative to public/images.
|
||||
const IMG_AJAX_LOADER_OVERLAY = '/ajax-loader-overlay.gif';
|
||||
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the asset manager for script and styles.
|
||||
*
|
||||
* Must be called early, before init, else special measures are needed.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function initialize_scripts_and_styles() {
|
||||
Types_Asset_Manager::get_instance();
|
||||
}
|
||||
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
private function __construct() { }
|
||||
|
||||
|
||||
/**
|
||||
* For given image, return it's relative URL.
|
||||
*
|
||||
* @param string $image Image defined as a constant of Types_Assets.
|
||||
* @return string Relative URL of the image.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_image_url( $image ) {
|
||||
return TYPES_RELPATH . '/public/images' . $image;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Represents a single dialog box whose template will be rendered on the page when an instance of this class is
|
||||
* created. Enqueues all the assets needed for displaying it.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Dialog_Box extends Toolset_DialogBoxes {
|
||||
|
||||
/** @var array */
|
||||
private $context;
|
||||
|
||||
/** @var Twig_Environment */
|
||||
private $twig;
|
||||
|
||||
/** @var string */
|
||||
private $template_name;
|
||||
|
||||
/** @var string */
|
||||
private $dialog_id;
|
||||
|
||||
|
||||
/**
|
||||
* Types_Dialog_Box constructor.
|
||||
*
|
||||
* Should be called during the 'current_screen' action, not sooner or later.
|
||||
*
|
||||
* @param string $dialog_id Unique ID (at least within the page) used to reference the dialog in JS.
|
||||
* @param Twig_Environment $twig Prepared Twig environment.
|
||||
* @param array $context Twig context for the dialog template.
|
||||
* @param string $template_name Twig template name that will be recognized by the provided environment.
|
||||
* @param bool $late_register_assets Whether to run late_register_assets() or not.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function __construct( $dialog_id, $twig, $context, $template_name, $late_register_assets = true ) {
|
||||
|
||||
$current_screen = get_current_screen();
|
||||
parent::__construct( array( $current_screen->id ) );
|
||||
|
||||
$this->dialog_id = $dialog_id;
|
||||
$this->twig = $twig;
|
||||
$this->context = $context;
|
||||
$this->template_name = $template_name;
|
||||
|
||||
if( $late_register_assets ) {
|
||||
$this->late_register_assets();
|
||||
}
|
||||
|
||||
// We're going to render on the page we're creating this instance.
|
||||
$this->init_screen_render();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a predefined Twig template.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function template() {
|
||||
printf(
|
||||
'<script type="text/html" id="%s">%s</script>',
|
||||
esc_attr( $this->dialog_id ),
|
||||
$this->twig->render( $this->template_name, $this->context )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Manually register dialog assets in Types_Asset_Manager because by now we have already missed the
|
||||
* toolset_add_registered_styles and toolset_add_registered_scripts filters (but there is still enough time
|
||||
* to enqueue).
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
protected function late_register_assets() {
|
||||
/*
|
||||
* Toolset_DialogBoxes::register_styles() no longer exists
|
||||
* https://git.onthegosystems.com/toolset/toolset-common/commit/cb176128ac8382cebbad46a39848b4c76fdcc7a7
|
||||
*
|
||||
// Get script and styles from parent methods, and register them manually.
|
||||
$styles = $this->register_styles( array() );
|
||||
foreach( $styles as $style ) {
|
||||
Types_Asset_Manager::get_instance()->register_toolset_style( $style );
|
||||
}
|
||||
*/
|
||||
|
||||
$scripts = $this->register_scripts( array() );
|
||||
foreach( $scripts as $script ) {
|
||||
Types_Asset_Manager::get_instance()->register_toolset_script( $script );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Embedded controller.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Embedded {
|
||||
|
||||
private function __construct() {
|
||||
// disable pages
|
||||
add_filter( 'types_register_pages', '__return_false' );
|
||||
|
||||
// disable information table
|
||||
add_filter( 'types_information_table', '__return_false' );
|
||||
}
|
||||
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
public static function initialize() {
|
||||
if( file_exists( TYPES_ABSPATH . '/embedded.lock' )
|
||||
|| ( defined( 'TYPES_EMBEDDED') && TYPES_EMBEDDED === true )
|
||||
) {
|
||||
new self();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
<?php
|
||||
|
||||
// WIP
|
||||
final class Types_Field_Type_Converter {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
private function __construct() {
|
||||
// Toolset Maps uses priority 10 for this filter, we need to run later and override.
|
||||
add_filter( 'wpcf_filter_field_control_change_type_allowed_types_from', array( $this, 'google_address_field_control_change_type_allowed_from' ), 15, 2 );
|
||||
}
|
||||
|
||||
|
||||
private $conversion_matrix = null;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a matrix of allowed field type conversions.
|
||||
*
|
||||
* For each field type as key it contains an array of types it can be converted into.
|
||||
*
|
||||
* Usually, you shouldn't use this method directly, but instead use dedicated methods for a specific field type.
|
||||
*
|
||||
* Note: An empty row for a field type can be interpreted in a way that any conversion is allowed. If that's not
|
||||
* desired, make sure each type can be converted to itself.
|
||||
*
|
||||
* Note: The conversion matrix is cached, so any used filters must be hooked into soon enough.
|
||||
*
|
||||
* @return string[][]|mixed
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_conversion_matrix() {
|
||||
|
||||
if( null == $this->conversion_matrix ) {
|
||||
|
||||
$simple_string_types = array(
|
||||
'audio', 'email', 'embed', 'file', 'google_address', 'image', 'numeric', 'phone', 'textfield',
|
||||
'url', 'video', 'colorpicker', 'textarea'
|
||||
);
|
||||
|
||||
$allowed_conversion_source = array(
|
||||
'audio' => $simple_string_types,
|
||||
'colorpicker' => $simple_string_types,
|
||||
'checkbox' => array( 'checkbox' ),
|
||||
'checkboxes' => array( 'checkboxes' ),
|
||||
'date' => array( 'date' ),
|
||||
'email' => $simple_string_types,
|
||||
'embed' => $simple_string_types,
|
||||
'file' => $simple_string_types,
|
||||
'google_address' => $simple_string_types,
|
||||
'image' => $simple_string_types,
|
||||
'numeric' => $simple_string_types,
|
||||
'phone' => $simple_string_types,
|
||||
'radio' => array( 'radio' ),
|
||||
'select' => array( 'select' ),
|
||||
'skype' => array( 'skype' ),
|
||||
'textarea' => $simple_string_types,
|
||||
'textfield' => $simple_string_types,
|
||||
'url' => $simple_string_types,
|
||||
'video' => $simple_string_types,
|
||||
'wysiwyg' => array( 'wysiwyg' ),
|
||||
);
|
||||
|
||||
|
||||
$filtered_conversion_matrix = array();
|
||||
foreach( $allowed_conversion_source as $field_type_slug => $allowed_conversions ) {
|
||||
|
||||
/**
|
||||
* wpcf_filter_field_control_change_type_allowed_types_from
|
||||
*
|
||||
* Filter the field types that you can switch to, given a type field
|
||||
*
|
||||
* @param string[] $allowed_conversions Valid targets for a given origin type.
|
||||
* @param string $field_type_slug Field type to switch from.
|
||||
*
|
||||
* @since 1.8.9
|
||||
*/
|
||||
$filtered_conversion_matrix[ $field_type_slug ] = apply_filters( 'wpcf_filter_field_control_change_type_allowed_types_from', $allowed_conversions, $field_type_slug );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* wpcf_filter_field_control_change_type_allowed_types
|
||||
*
|
||||
* Filter the pairs field type origin -> valid field type targets when using the fields control change field type feature
|
||||
*
|
||||
* @param array $allowed_conversion_matrix Valid correspondence between field types and target field types
|
||||
*
|
||||
* @since 1.8.9
|
||||
*/
|
||||
$result = apply_filters( 'wpcf_filter_field_control_change_type_allowed_types', $filtered_conversion_matrix );
|
||||
|
||||
|
||||
$this->conversion_matrix = $result;
|
||||
}
|
||||
|
||||
return $this->conversion_matrix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Types_Field_Type_Definition $type
|
||||
* @return Types_Field_Type_Definition[]
|
||||
*/
|
||||
public function get_possible_conversions( $type ) {
|
||||
|
||||
if( ! $type instanceof Types_Field_Type_Definition ) {
|
||||
throw new InvalidArgumentException( 'Not a field type definition' );
|
||||
}
|
||||
|
||||
$matrix = $this->get_conversion_matrix();
|
||||
$allowed_slugs = wpcf_ensarr( wpcf_getarr( $matrix, $type->get_slug() ) );
|
||||
$allowed_types = Types_Field_Type_Definition_Factory::get_instance()->load_multiple_definitions( $allowed_slugs );
|
||||
return $allowed_types;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Types_Field_Type_Definition $from_type
|
||||
* @param Types_Field_Type_Definition $to_type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_conversion_possible( $from_type, $to_type ) {
|
||||
|
||||
if( ! $from_type instanceof Types_Field_Type_Definition || ! $to_type instanceof Types_Field_Type_Definition ) {
|
||||
throw new InvalidArgumentException( 'Not a field type definition' );
|
||||
}
|
||||
|
||||
$possible_conversions = $this->get_possible_conversions( $from_type );
|
||||
|
||||
return in_array( $to_type->get_slug(), array_keys( $possible_conversions ) );
|
||||
}
|
||||
|
||||
|
||||
public function is_conversion_two_way( $type_1, $type_2 ) {
|
||||
if( ! $type_1 instanceof Types_Field_Type_Definition || ! $type_2 instanceof Types_Field_Type_Definition ) {
|
||||
throw new InvalidArgumentException( 'Not a field type definition' );
|
||||
}
|
||||
|
||||
return ( $this->is_conversion_possible( $type_1, $type_2 ) && $this->is_conversion_possible( $type_2, $type_1 ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disallow certain conversion from or to google address field.
|
||||
*
|
||||
* This is hooked into the wpcf_filter_field_control_change_type_allowed_types_from filter with higher priority
|
||||
* than the Toolset Maps hook that adds the google_address field type to the conversion matrix.
|
||||
*
|
||||
* This way we can properly handle the allowed conversions not depending on the particular Toolset Maps version
|
||||
* that is active.
|
||||
*
|
||||
* @param string[] $targets Field type slugs TO which the conversion is allowed from $origin.
|
||||
* @param string $origin Field type slug FROM which the conversion can happen.
|
||||
*
|
||||
* @return string[] Updated $targets.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function google_address_field_control_change_type_allowed_from( $targets, $origin ) {
|
||||
|
||||
$disallowed_targets = array(
|
||||
Types_Field_Type_Definition_Factory::DATE,
|
||||
Types_Field_Type_Definition_Factory::CHECKBOX,
|
||||
Types_Field_Type_Definition_Factory::CHECKBOXES,
|
||||
Types_Field_Type_Definition_Factory::RADIO,
|
||||
Types_Field_Type_Definition_Factory::SELECT,
|
||||
Types_Field_Type_Definition_Factory::SKYPE,
|
||||
Types_Field_Type_Definition_Factory::WYSIWYG
|
||||
);
|
||||
|
||||
if( Types_Field_Type_Definition_Factory::GOOGLE_ADDRESS == $origin ) {
|
||||
// Here we're filtering possible conversions FROM google address field
|
||||
$safe_targets = array_diff( $targets, $disallowed_targets );
|
||||
$targets = $safe_targets;
|
||||
} else if( in_array( $origin, $disallowed_targets ) ) {
|
||||
// Here we're filtering possible conversions TO google address field from an undesired field type
|
||||
if( in_array( Types_Field_Type_Definition_Factory::GOOGLE_ADDRESS, $targets ) ) {
|
||||
$item_pos = array_search( Types_Field_Type_Definition_Factory::GOOGLE_ADDRESS, $targets );
|
||||
unset( $targets[ $item_pos ] );
|
||||
}
|
||||
}
|
||||
return $targets;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,187 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Static class for shortcut functions related to field types, groups, definitions and instances.
|
||||
* @since 1.9
|
||||
*/
|
||||
final class Types_Field_Utils {
|
||||
|
||||
private function __construct() { }
|
||||
|
||||
|
||||
// Field domains supported by the page.
|
||||
const DOMAIN_POSTS = 'posts';
|
||||
const DOMAIN_USERS = 'users';
|
||||
const DOMAIN_TERMS = 'terms';
|
||||
|
||||
// Since PHP 5.6, noooo!
|
||||
// const DOMAINS = array( self::DOMAIN_POSTS, self::DOMAIN_USERS, self::DOMAIN_TERMS );
|
||||
|
||||
|
||||
/**
|
||||
* Array of valid field domains.
|
||||
*
|
||||
* Replacement for self::DOMAINS because damn you old PHP versions.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
public static function get_domains() {
|
||||
return array( self::DOMAIN_POSTS, self::DOMAIN_USERS, self::DOMAIN_TERMS );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $domain
|
||||
*
|
||||
* @return WPCF_Field_Definition_Factory
|
||||
* @deprecated Use WPCF_Field_Definition_Factory::get_factory_by_domain() instead.
|
||||
*/
|
||||
public static function get_definition_factory_by_domain( $domain ) {
|
||||
switch( $domain ) {
|
||||
case self::DOMAIN_POSTS:
|
||||
return WPCF_Field_Definition_Factory_Post::get_instance();
|
||||
case self::DOMAIN_USERS:
|
||||
return WPCF_Field_Definition_Factory_User::get_instance();
|
||||
case self::DOMAIN_TERMS:
|
||||
return WPCF_Field_Definition_Factory_Term::get_instance();
|
||||
default:
|
||||
throw new InvalidArgumentException( 'Invalid field domain.' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For a given field domain, return the appropriate field group factory instance.
|
||||
*
|
||||
* @param string $domain
|
||||
*
|
||||
* @return Types_Field_Group_Factory
|
||||
* @since 2.0
|
||||
* @deprecated Use Types_Field_Group_Factory::get_factory_by_domain() instead.
|
||||
*/
|
||||
public static function get_group_factory_by_domain( $domain ) {
|
||||
switch( $domain ) {
|
||||
case self::DOMAIN_POSTS:
|
||||
return Types_Field_Group_Post_Factory::get_instance();
|
||||
case self::DOMAIN_USERS:
|
||||
return Types_Field_Group_User_Factory::get_instance();
|
||||
case self::DOMAIN_TERMS:
|
||||
return Types_Field_Group_Term_Factory::get_instance();
|
||||
default:
|
||||
throw new InvalidArgumentException( 'Invalid field domain.' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the correct field group factory for provided underlying post type of the field group.
|
||||
*
|
||||
* This should not be needed from outside the legacy code.
|
||||
*
|
||||
* @param string $group_post_type
|
||||
* @return Types_Field_Group_Factory
|
||||
* @throws InvalidArgumentException when the post type doesn't belong to any field group.
|
||||
* @since 2.2.4
|
||||
*/
|
||||
public static function get_group_factory_by_post_type( $group_post_type ) {
|
||||
$domains = self::get_domains();
|
||||
foreach( $domains as $domain ) {
|
||||
$factory = Types_Field_Group_Factory::get_factory_by_domain( $domain );
|
||||
if( $factory->get_post_type() == $group_post_type ) {
|
||||
return $factory;
|
||||
}
|
||||
}
|
||||
throw new InvalidArgumentException( 'Invalid field group post type.' );
|
||||
}
|
||||
|
||||
|
||||
private static $domain_legacy_value_map = array(
|
||||
self::DOMAIN_POSTS => 'postmeta',
|
||||
self::DOMAIN_USERS => 'usermeta',
|
||||
self::DOMAIN_TERMS => 'termmeta'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Translate a field domain into a "meta_type" value, which is used in field definition arrays.
|
||||
*
|
||||
* @param string $domain
|
||||
* @return string
|
||||
* @since 2.0
|
||||
*/
|
||||
public static function domain_to_legacy_meta_type( $domain ) {
|
||||
return wpcf_getarr( self::$domain_legacy_value_map, $domain );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translate a "meta_type" value into a field domain name.
|
||||
*
|
||||
* @param $meta_type
|
||||
* @return string
|
||||
* @since 2.1
|
||||
*/
|
||||
public static function legacy_meta_type_to_domain( $meta_type ) {
|
||||
$map = array_flip( self::$domain_legacy_value_map );
|
||||
return wpcf_getarr( $map, $meta_type );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a term field instance.
|
||||
*
|
||||
* @param string $field_slug Slug of existing field definition.
|
||||
* @param int $term_id ID of the term where the field belongs.
|
||||
*
|
||||
* @return null|WPCF_Field_Instance Field instance or null if an error occurs.
|
||||
* @since 1.9
|
||||
*/
|
||||
public static function create_term_field_instance( $field_slug, $term_id ) {
|
||||
try {
|
||||
return new WPCF_Field_Instance_Term( WPCF_Field_Definition_Factory_Term::get_instance()->load_field_definition( $field_slug ), $term_id );
|
||||
} catch( Exception $e ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Obtain toolset-forms "field configuration", which is an array of settings for specific field instance.
|
||||
*
|
||||
* @param WPCF_Field_Instance $field
|
||||
*
|
||||
* @since 1.9
|
||||
* @return array
|
||||
*/
|
||||
public static function get_toolset_forms_field_config( $field ) {
|
||||
return wptoolset_form_filter_types_field(
|
||||
$field->get_definition()->get_definition_array(),
|
||||
$field->get_object_id()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gather an unique array of field definitions from given groups.
|
||||
*
|
||||
* The groups are expected to belong to the same domain (term/post/user), otherwise problems may occur when
|
||||
* field slugs conflict.
|
||||
*
|
||||
* @param Types_Field_Group[] $field_groups
|
||||
* @return WPCF_Field_Definition[]
|
||||
* @since 1.9
|
||||
*/
|
||||
public static function get_field_definitions_from_groups( $field_groups ) {
|
||||
$field_definitions = array();
|
||||
foreach( $field_groups as $group ) {
|
||||
$group_field_definitions = $group->get_field_definitions();
|
||||
|
||||
foreach( $group_field_definitions as $field_definition ) {
|
||||
$field_definitions[ $field_definition->get_slug() ] = $field_definition;
|
||||
}
|
||||
}
|
||||
return $field_definitions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Main front-end controller for Types.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Frontend {
|
||||
|
||||
public static function initialize() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,698 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types import and export controller.
|
||||
*
|
||||
* Currently it only contains new code that is hooked into legacy methods plus a bunch of temporary workarounds, but
|
||||
* has the ambition to become the central point of handling all import and export-related activities.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
final class Types_Import_Export {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if ( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __clone() {
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Non-associative arrays which are to be exported to XML need to contain this key. Its value
|
||||
* determines node names of all other items. For example,
|
||||
*
|
||||
* 'terms' => array( 'a', 'b', '__key' => 'term' )
|
||||
*
|
||||
* will translate into
|
||||
*
|
||||
* <terms>
|
||||
* <term>a</term>
|
||||
* <term>b</term>
|
||||
* </terms>
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
const XML_KEY = '__key';
|
||||
|
||||
|
||||
/**
|
||||
* Hash and checksum is used to check if a certain post types, custom field groups inside a module is changed.
|
||||
* It's using MD5hash. This will be used by module manager to check if the module is updated (meaning the types
|
||||
* definition) has changed. And it will alert the user that he is importing a different module.
|
||||
*
|
||||
* @link https://onthegosystems.myjetbrains.com/youtrack/issue/types-749#comment=102-105945
|
||||
*/
|
||||
const XML_KEY_CHECKSUM = 'checksum';
|
||||
const XML_KEY_HASH = 'hash';
|
||||
|
||||
|
||||
/**
|
||||
* '__types_id' is used as a unique identifier for CPT,Types taxonomy, custom fields groups, etc. As for the
|
||||
* allowed values, it's usually using a slug as an identifier since this will not change during import/export.
|
||||
* IDs on the otherhand will change after import.
|
||||
*
|
||||
* Now '__types_title' is just the title/label name corresponding to the '__types_id'.
|
||||
*
|
||||
* @link https://onthegosystems.myjetbrains.com/youtrack/issue/types-749#comment=102-105945
|
||||
*/
|
||||
const XML_TYPES_ID = '__types_id';
|
||||
const XML_TYPES_TITLE = '__types_title';
|
||||
|
||||
|
||||
/** Element name for a single field group. */
|
||||
const XML_KEY_GROUP = 'group';
|
||||
|
||||
|
||||
/** Element name for a single field definition. */
|
||||
const XML_KEY_FIELD = 'field';
|
||||
|
||||
|
||||
/**
|
||||
* Completely handle retrieving export data for field groups of one domain.
|
||||
*
|
||||
* @param string $domain Valid field domain.
|
||||
*
|
||||
* @return array Exported field groups.
|
||||
* @since 2.1
|
||||
*/
|
||||
public function export_field_groups_for_domain( $domain ) {
|
||||
|
||||
$group_factory = Types_Field_Utils::get_group_factory_by_domain( $domain );
|
||||
$all_groups = $group_factory->query_groups();
|
||||
|
||||
// Each group will handle its own export.
|
||||
$results = array();
|
||||
foreach ( $all_groups as $field_group ) {
|
||||
$results[] = $field_group->get_export_object();
|
||||
}
|
||||
|
||||
$results[ self::XML_KEY ] = self::XML_KEY_GROUP;
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Completely handle retrieving export data for field definitions of one domain.
|
||||
*
|
||||
* @param string $domain Valid field domain.
|
||||
*
|
||||
* @return array Exported field definitions.
|
||||
* @since 2.1
|
||||
*/
|
||||
public function export_field_definitions_for_domain( $domain ) {
|
||||
|
||||
$definition_factory = Types_Field_Utils::get_definition_factory_by_domain( $domain );
|
||||
$all_definitions = $definition_factory->query_definitions( array( 'filter' => 'types' ) );
|
||||
|
||||
// Each field definition will handle its own export.
|
||||
$results = array();
|
||||
/** @var WPCF_Field_Definition $field_definition */
|
||||
foreach ( $all_definitions as $field_definition ) {
|
||||
$results[] = $field_definition->get_export_object();
|
||||
}
|
||||
|
||||
$results[ self::XML_KEY ] = self::XML_KEY_FIELD;
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a checksum for an to-be-exported object and store it.
|
||||
*
|
||||
* @param array $data An associative array representing an object.
|
||||
* @param null|string[] $keys_for_checksum Array keys that should be used when generating the checksum. If null,
|
||||
* the whole $data is used.
|
||||
* @param null|string[] $keys_to_remove Array keys that should be _not_ used when generating the checksum.
|
||||
*
|
||||
* @return array The updated $data with XML_KEY_CHECKSUM and XML_KEY_HASH set.
|
||||
* @since 2.1
|
||||
*/
|
||||
public function add_checksum_to_object( $data, $keys_for_checksum = null, $keys_to_remove = null ) {
|
||||
|
||||
// pluck requested keys
|
||||
if ( null == $keys_for_checksum ) {
|
||||
$checksum_source = $data;
|
||||
} else {
|
||||
$checksum_source = array();
|
||||
foreach ( $data as $key => $value ) {
|
||||
if ( in_array( $key, $keys_for_checksum ) ) {
|
||||
$checksum_source[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unset undesired keys
|
||||
if ( is_array( $keys_to_remove ) ) {
|
||||
$checksum_source = $this->unset_recursive( $checksum_source, $keys_to_remove );
|
||||
}
|
||||
|
||||
$checksum = $this->generate_checksum( $checksum_source );
|
||||
|
||||
$data[ self::XML_KEY_CHECKSUM ] = $checksum;
|
||||
$data[ self::XML_KEY_HASH ] = $checksum;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unset keys from a multidimensional array.
|
||||
*
|
||||
* @param array $unset_from The source array.
|
||||
* @param array $unset_what Definition of keys that need to be unset. Each element of this array can be either
|
||||
* a string, in which case it represents an key to be removed on the top level, or an 'key' => array( ... )
|
||||
* value, in which case the unsetting will happen in $unset_from['key'].
|
||||
*
|
||||
* For example, unsetting array( 'c', 'd' => array( 'b' ) ) from
|
||||
*
|
||||
* array( 'a' => 1, 'b' => 2, 'c' => array( 'a' => 1 ), 'd' => array( 'a' => 1, 'b' => 2 ) )
|
||||
*
|
||||
* will return
|
||||
*
|
||||
* array( 'a' => 1, 'b' => 2, 'd' => array( 'a' => 1 ) )
|
||||
*
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
private function unset_recursive( $unset_from, $unset_what ) {
|
||||
if ( is_array( $unset_from ) ) {
|
||||
|
||||
foreach ( $unset_what as $key => $value ) {
|
||||
|
||||
if ( is_array( $value ) && isset( $unset_from[ $key ] ) ) {
|
||||
$unset_from[ $key ] = $this->unset_recursive( $unset_from[ $key ], $value );
|
||||
} else {
|
||||
unset( $unset_from[ $value ] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $unset_from;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add standard object annotation XML_TYPES_ID and XML_TYPES_TITLE.
|
||||
*
|
||||
* @param array $data An associative array representing an object.
|
||||
* @param string $title
|
||||
* @param string $id
|
||||
*
|
||||
* @return array Updated $data.
|
||||
* @since 2.1
|
||||
*/
|
||||
public function annotate_object( $data, $title, $id ) {
|
||||
$data[ self::XML_TYPES_ID ] = $id;
|
||||
$data[ self::XML_TYPES_TITLE ] = $title;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a checksum for given object.
|
||||
*
|
||||
* Note: Do not touch this.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return string Checksum
|
||||
* @since 2.1
|
||||
*/
|
||||
private function generate_checksum( $data ) {
|
||||
return md5( maybe_serialize( $this->ksort_as_string( $data ) ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sort a multidimensional array by keys recursively.
|
||||
*
|
||||
* @param array|mixed $data
|
||||
*
|
||||
* @return array|mixed Sorted $data.
|
||||
* @since 2.1
|
||||
*/
|
||||
private function ksort_as_string( $data ) {
|
||||
if ( is_array( $data ) ) {
|
||||
ksort( $data, SORT_STRING );
|
||||
foreach ( $data as $key => $value ) {
|
||||
$data[ $key ] = $this->ksort_as_string( $value );
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import field definitions for given domain.
|
||||
*
|
||||
* Note: Currently only term fields are supported.
|
||||
*
|
||||
* @param string $domain Valid field domain.
|
||||
* @param SimpleXMLElement $data Import data from XML.
|
||||
* @param string $fields_key Node name where the field definitions can be found.
|
||||
* @param bool $delete_other_fields If true, fields that are not being imported will be deleted from the site.
|
||||
* @param array $field_settings Part of $_POST from the import form related to these fields.
|
||||
* @param array $args Used for making skip/overwrite decisions per item (used for toolset-based themes import)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function process_field_definition_import_per_domain(
|
||||
$domain,
|
||||
$data,
|
||||
$fields_key,
|
||||
$delete_other_fields,
|
||||
$field_settings,
|
||||
$args = array()
|
||||
) {
|
||||
|
||||
$results = array();
|
||||
|
||||
$fields_to_preserve = array();
|
||||
|
||||
$fields_import_data = array();
|
||||
if ( isset( $data->$fields_key ) ) {
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$fields_import_data = $this->simplexmlelement_to_object( $data->$fields_key, true );
|
||||
$fields_import_data = isset( $fields_import_data[ Types_Import_Export::XML_KEY_FIELD ] )
|
||||
? $fields_import_data[ Types_Import_Export::XML_KEY_FIELD ] : array();
|
||||
}
|
||||
|
||||
foreach ( $fields_import_data as $field_import_data ) {
|
||||
$field_slug = $field_import_data['slug'];
|
||||
|
||||
// check if via $_POST the field is allowed
|
||||
$import_field = isset( $field_settings[ $field_slug ] ) && isset( $field_settings[ $field_slug ]['add'] );
|
||||
|
||||
// on toolset based themes we allow every field
|
||||
$import_field = array_key_exists( 'toolset-themes', $args ) ? true : $import_field;
|
||||
|
||||
// User choices on import/update process (TBT toolset-based themes)
|
||||
$field_import_data = tbt_user_choice( $args, $field_import_data );
|
||||
if ( array_key_exists( 'add', $field_import_data ) ) {
|
||||
$import_field = $field_import_data['add'];
|
||||
}
|
||||
|
||||
if ( $import_field ) {
|
||||
$result = $this->import_field_definition( $domain, $field_import_data );
|
||||
if ( $result['is_success'] ) {
|
||||
$fields_to_preserve[] = $field_slug;
|
||||
}
|
||||
$results[] = array(
|
||||
'type' => ( $result['is_success'] ? 'success' : 'error' ),
|
||||
'content' => $result['display_message']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$delete_results = $this->maybe_delete_fields( $domain, $delete_other_fields, $fields_to_preserve );
|
||||
$results = array_merge( $results, $delete_results );
|
||||
|
||||
return $results;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $domain
|
||||
* @param bool $delete_other_fields
|
||||
* @param string[] $fields_to_preserve Array of field slugs that should be preserved.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function maybe_delete_fields( $domain, $delete_other_fields, $fields_to_preserve ) {
|
||||
|
||||
$results = array();
|
||||
|
||||
$definition_factory = Types_Field_Utils::get_definition_factory_by_domain( $domain );
|
||||
$option_name = $definition_factory->get_option_name_workaround();
|
||||
|
||||
if ( $delete_other_fields ) {
|
||||
|
||||
$fields_existing = wpcf_admin_fields_get_fields( false, false, false, $option_name, false, true );
|
||||
|
||||
foreach ( $fields_existing as $key => $existing_field_definition ) {
|
||||
|
||||
if ( ! empty( $existing_field_definition['data']['controlled'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$existing_field_slug = $existing_field_definition['slug'];
|
||||
|
||||
if ( ! in_array( $existing_field_slug, $fields_to_preserve ) ) {
|
||||
$results[] = array(
|
||||
'type' => 'success',
|
||||
'content' => sprintf(
|
||||
__( 'User field "%s" deleted', 'wpcf' ),
|
||||
$existing_field_definition['name']
|
||||
)
|
||||
);
|
||||
unset( $fields_existing[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
update_option( $option_name, $fields_existing );
|
||||
}
|
||||
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $domain
|
||||
* @param array $definition_array_import Field definition array (will contain some additional elements from the import file).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function import_field_definition( $domain, $definition_array_import ) {
|
||||
|
||||
$definition = array(
|
||||
'id' => $definition_array_import['id'],
|
||||
'name' => $definition_array_import['name'],
|
||||
'description' => isset( $definition_array_import['description'] ) ? $definition_array_import['description']
|
||||
: '',
|
||||
'type' => $definition_array_import['type'],
|
||||
'slug' => $definition_array_import['slug'],
|
||||
'data' => ( isset( $definition_array_import['data'] ) && is_array( $definition_array_import['data'] ) )
|
||||
? $definition_array_import['data'] : array()
|
||||
);
|
||||
|
||||
if ( isset( $definition_array_import['meta_key'] ) ) {
|
||||
$definition['meta_key'] = $definition_array_import['meta_key'];
|
||||
}
|
||||
|
||||
// WPML
|
||||
global $iclTranslationManagement;
|
||||
if ( ! empty( $iclTranslationManagement ) && isset( $definition['wpml_action'] ) ) {
|
||||
$iclTranslationManagement->settings['custom_fields_translation'][ wpcf_types_get_meta_prefix( $definition ) . $definition['slug'] ] = $definition['wpml_action'];
|
||||
$iclTranslationManagement->save_settings();
|
||||
}
|
||||
|
||||
$definition_factory = Types_Field_Utils::get_definition_factory_by_domain( $domain );
|
||||
$definition_factory->set_field_definition_workaround( $definition['slug'], $definition );
|
||||
|
||||
return array(
|
||||
'is_success' => true,
|
||||
'display_message' => sprintf( __( 'Term field "%s" added/updated', 'wpcf' ), $definition['name'] )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import field definitions for given domain.
|
||||
*
|
||||
* Note: Currently only term fields are supported.
|
||||
*
|
||||
* @param string $domain Valid field domain.
|
||||
* @param SimpleXMLElement $data Import data from XML.
|
||||
* @param string $groups_key Node name where the field groups can be found.
|
||||
* @param bool $bulk_overwrite_groups If true, all (conflicting) groups will be overwritten by the ones from import.
|
||||
* @param bool $delete_other_groups If true, groups that are not being imported will be deleted from the site.
|
||||
* @param array $group_settings Part of $_POST from the import form related to these groups.
|
||||
* @param array $args Used for making skip/overwrite decisions per item (used for toolset-based themes import)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function process_field_group_import_per_domain(
|
||||
$domain,
|
||||
$data,
|
||||
$groups_key,
|
||||
$bulk_overwrite_groups,
|
||||
$delete_other_groups,
|
||||
$group_settings,
|
||||
$args = array()
|
||||
) {
|
||||
|
||||
$results = array();
|
||||
$groups_to_preserve = array();
|
||||
|
||||
$groups_import_data = array();
|
||||
if ( isset( $data->$groups_key ) ) {
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$groups_import_data = $this->simplexmlelement_to_object( $data->$groups_key, true );
|
||||
$groups_import_data = isset( $groups_import_data[ Types_Import_Export::XML_KEY_GROUP ] )
|
||||
? $groups_import_data[ Types_Import_Export::XML_KEY_GROUP ] : array();
|
||||
}
|
||||
|
||||
foreach ( $groups_import_data as $group ) {
|
||||
|
||||
// ID of group from the import file
|
||||
$import_group_id = wpcf_getarr( $group, Types_Field_Group::XML_ID );
|
||||
|
||||
|
||||
if ( array_key_exists( 'toolset-themes', $args ) ) {
|
||||
// Toolset Themes Import Way
|
||||
$group = tbt_user_choice( $args, $group );
|
||||
|
||||
$group_should_be_imported = $this->tbt_group_should_be_imported( $group );
|
||||
|
||||
if ( array_key_exists( 'add', $group ) ) {
|
||||
$group_actions['add'] = $group['add'];
|
||||
}
|
||||
} else {
|
||||
// Types Import Way
|
||||
$group_actions = wpcf_getarr( $group_settings, $import_group_id, array( 'add' => true ) );
|
||||
$group_should_be_imported = isset( $group_actions['add'] );
|
||||
}
|
||||
|
||||
if ( $group_should_be_imported ) {
|
||||
if ( $bulk_overwrite_groups // bulk overwrite (types import/export page)
|
||||
|| ( // OR...
|
||||
array_key_exists( 'toolset-themes', $args ) // import with toolset themes
|
||||
&& ( // AND...
|
||||
! array_key_exists( 'update', $group ) // ADD for group is not SET (new item)
|
||||
|| $group['update'] // OR... UPDATE is set for item (user choice)
|
||||
)
|
||||
)
|
||||
) {
|
||||
// OVERWRITE
|
||||
$group_action = 'update';
|
||||
} else {
|
||||
$group_action = wpcf_getarr( $group_actions, 'update', 'add', array( 'add', 'update' ) );
|
||||
}
|
||||
} else {
|
||||
$group_action = 'nothing';
|
||||
}
|
||||
|
||||
$result = null;
|
||||
|
||||
switch ( $group_action ) {
|
||||
case 'add':
|
||||
$result = $this->import_field_group( $domain, $group, 'create_new' );
|
||||
break;
|
||||
case 'update':
|
||||
$result = $this->import_field_group( $domain, $group, 'overwrite' );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( null != $result ) {
|
||||
$results[] = array(
|
||||
'type' => ( $result['is_success'] ? 'success' : 'error' ),
|
||||
'content' => $result['display_message']
|
||||
);
|
||||
if ( $result['is_success'] ) {
|
||||
$groups_to_preserve[] = $result['new_group_id'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$delete_results = $this->maybe_delete_groups( $domain, $delete_other_groups, $groups_to_preserve );
|
||||
$results = array_merge( $results, $delete_results );
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $domain
|
||||
* @param bool $delete_other_groups
|
||||
* @param int[] $groups_to_preserve
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function maybe_delete_groups( $domain, $delete_other_groups, $groups_to_preserve ) {
|
||||
|
||||
$results = array();
|
||||
if ( $delete_other_groups && ! empty( $groups_to_preserve ) ) {
|
||||
$group_factory = Types_Field_Utils::get_group_factory_by_domain( $domain );
|
||||
$all_groups = $group_factory->query_groups();
|
||||
|
||||
foreach ( $all_groups as $group_to_delete ) {
|
||||
if ( ! in_array( $group_to_delete->get_id(), $groups_to_preserve ) ) {
|
||||
|
||||
$deleted_group_name = $group_to_delete->get_name();
|
||||
$deleted = wp_delete_post( $group_to_delete->get_id(), true );
|
||||
if ( ! $deleted ) {
|
||||
$results[] = array(
|
||||
'type' => 'error',
|
||||
'content' => sprintf( __( 'Term field group "%s" delete failed', 'wpcf' ),
|
||||
$deleted_group_name )
|
||||
);
|
||||
} else {
|
||||
$results[] = array(
|
||||
'type' => 'success',
|
||||
'content' => sprintf( __( 'Term field group "%s" deleted', 'wpcf' ), $deleted_group_name )
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $domain Valid field domain
|
||||
* @param array $group Field group import data as associative array.
|
||||
* @param string $conflict_resolution = 'overwrite'|'create_new' Defines how to handle a situation when a
|
||||
* field group already exists in the database.
|
||||
*
|
||||
* @return array Import results:
|
||||
* 'is_success' bool
|
||||
* 'display_message' string
|
||||
* 'new_group_id' int
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public function import_field_group( $domain, $group, $conflict_resolution ) {
|
||||
|
||||
$group_slug = wpcf_getarr( $group, Types_Field_Group::XML_SLUG );
|
||||
|
||||
$group_factory = Types_Field_Utils::get_group_factory_by_domain( $domain );
|
||||
|
||||
$existing_groups = $group_factory->query_groups( array( 'name' => $group_slug ) );
|
||||
$group_already_exists = ( count( $existing_groups ) > 0 );
|
||||
|
||||
$new_post = array(
|
||||
'post_status' => $group['post_status'],
|
||||
'post_type' => $group_factory->get_post_type(),
|
||||
'post_title' => $group['post_title'],
|
||||
'post_content' => ! empty( $group['post_content'] ) ? $group['post_content'] : '',
|
||||
);
|
||||
|
||||
$update_existing = ( $group_already_exists && 'overwrite' == $conflict_resolution );
|
||||
|
||||
if ( $update_existing ) {
|
||||
$existing_group = $existing_groups[0];
|
||||
$new_post['ID'] = $existing_group->get_id();
|
||||
$new_group_id = wp_update_post( $new_post );
|
||||
} else {
|
||||
$new_group_id = wp_insert_post( $new_post, true );
|
||||
}
|
||||
|
||||
$is_success = ( ! is_wp_error( $new_group_id ) && 0 < $new_group_id );
|
||||
|
||||
// Update group's postmeta
|
||||
if ( $is_success && ! empty( $group['meta'] ) ) {
|
||||
foreach ( $group['meta'] as $meta_key => $meta_value ) {
|
||||
if ( Types_Field_Group_Term::POSTMETA_ASSOCIATED_TAXONOMY == $meta_key ) {
|
||||
$meta_values = explode( ',', $meta_value );
|
||||
delete_post_meta( $new_group_id, $meta_key );
|
||||
foreach ( $meta_values as $single_meta_value ) {
|
||||
update_post_meta( $new_group_id, $meta_key, $single_meta_value );
|
||||
}
|
||||
} else {
|
||||
update_post_meta( $new_group_id, $meta_key, $meta_value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create display message
|
||||
if ( $is_success ) {
|
||||
if ( $update_existing ) {
|
||||
$display_message = sprintf( __( 'Term field group "%s" updated', 'wpcf' ), $group['post_title'] );
|
||||
} else {
|
||||
$display_message = sprintf( __( 'Term field group "%s" added', 'wpcf' ), $group['post_title'] );
|
||||
}
|
||||
} else {
|
||||
if ( $update_existing ) {
|
||||
$display_message = sprintf( __( 'Term field group "%s" update failed', 'wpcf' ), $group['post_title'] );
|
||||
} else {
|
||||
$display_message = sprintf( __( 'Term field group "%s" insert failed', 'wpcf' ), $group['post_title'] );
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'is_success' => $is_success,
|
||||
'display_message' => $display_message,
|
||||
'new_group_id' => $new_group_id
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param SimpleXMLElement $element
|
||||
* @param bool $allways_expand_top_level
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function simplexmlelement_to_object( $element, $allways_expand_top_level = false ) {
|
||||
$text_content = trim( (string) $element );
|
||||
if ( ! empty( $text_content ) ) {
|
||||
return $text_content;
|
||||
}
|
||||
|
||||
if ( $element->count() > 0 ) {
|
||||
$results_by_node_name = array();
|
||||
|
||||
/** @var SimpleXMLElement $child */
|
||||
foreach ( $element->children() as $child ) {
|
||||
$child_name = $child->getName();
|
||||
|
||||
if ( ! isset( $results_by_node_name[ $child_name ] ) ) {
|
||||
$results_by_node_name[ $child_name ] = array();
|
||||
}
|
||||
|
||||
$results_by_node_name[ $child_name ][] = $this->simplexmlelement_to_object( $child, false );
|
||||
}
|
||||
|
||||
$results = array();
|
||||
foreach ( $results_by_node_name as $node_name => $children ) {
|
||||
$take_only_first_child = ( count( $children ) == 1 && ! $allways_expand_top_level );
|
||||
$results[ $node_name ] = ( $take_only_first_child ? $children[0] : $children );
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if a group should be imported or not
|
||||
* This is only relevant for the import process of Toolset Themes
|
||||
*
|
||||
* @param $group
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function tbt_group_should_be_imported( $group ) {
|
||||
if ( array_key_exists( 'add', $group ) && $group['add'] === false ) {
|
||||
// the group already exists, but the user wants to keep his version ('add' === false)
|
||||
return false;
|
||||
}
|
||||
|
||||
// import group (initial import / overwrite / duplicate)
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Information_Controller
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Information_Controller {
|
||||
|
||||
protected $information;
|
||||
protected $twig;
|
||||
|
||||
private function requirements_met() {
|
||||
if(
|
||||
! current_user_can( 'manage_options' )
|
||||
|| ! apply_filters( 'types_information_table', true )
|
||||
|| $this->embedded_plugin_running()
|
||||
|| ! Types_Helper_Condition::get_post_type()
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* We don't want to show "archive" for media/pages and "template" for media
|
||||
*
|
||||
* @param $columns
|
||||
* @param $post_type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter_columns( $columns, $post_type ) {
|
||||
if( $post_type != 'attachment' && $post_type != 'page' ) {
|
||||
return $columns;
|
||||
}
|
||||
|
||||
if( array_key_exists( 'archive', $columns ) ) {
|
||||
unset( $columns['archive'] );
|
||||
}
|
||||
|
||||
if( $post_type == 'attachment' && array_key_exists( 'template', $columns ) ) {
|
||||
unset( $columns['template'] );
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function prepare() {
|
||||
if( ! $this->requirements_met() )
|
||||
return false;
|
||||
|
||||
// filter columns for specific post types
|
||||
add_filter( 'types_information_table_columns', array( $this, 'filter_columns' ), 10, 2 );
|
||||
|
||||
// twig
|
||||
$this->twig = new Types_Helper_Twig();
|
||||
|
||||
// script / style
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'on_admin_enqueue_scripts' ) );
|
||||
|
||||
/* data files */
|
||||
$data_files = array(
|
||||
TYPES_DATA . '/information/table/template.php',
|
||||
TYPES_DATA . '/information/table/archive.php',
|
||||
TYPES_DATA . '/information/table/views.php',
|
||||
TYPES_DATA . '/information/table/forms.php',
|
||||
);
|
||||
|
||||
$this->show_data_as_table_in_meta_box( $data_files );
|
||||
}
|
||||
|
||||
public function on_admin_enqueue_scripts() {
|
||||
|
||||
// script
|
||||
wp_enqueue_script(
|
||||
'types-information',
|
||||
TYPES_RELPATH . '/public/js/information.js',
|
||||
array( 'jquery-ui-dialog', 'wp-pointer' ),
|
||||
TYPES_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
// style
|
||||
wp_enqueue_style(
|
||||
'types-information',
|
||||
TYPES_RELPATH . '/public/css/information.css',
|
||||
array( 'wp-jquery-ui-dialog', 'wp-pointer' ),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
// load icons
|
||||
wp_enqueue_style(
|
||||
'onthegosystems-icons',
|
||||
WPCF_EMBEDDED_TOOLSET_RELPATH . '/onthego-resources/onthegosystems-icons/css/onthegosystems-icons.css',
|
||||
array(),
|
||||
TYPES_VERSION
|
||||
);
|
||||
}
|
||||
|
||||
protected function show_data_as_table_in_meta_box( $data_files ) {
|
||||
// prepare meta box
|
||||
$this->prepare_table_in_meta_box();
|
||||
|
||||
// thead
|
||||
$thead_views = $this->thead_views_template_archive_views_forms();
|
||||
|
||||
// load infos
|
||||
foreach( $data_files as $data_file ) {
|
||||
$this->load_data_to_table( $data_file );
|
||||
}
|
||||
|
||||
// table view
|
||||
$output_inner = $this->twig->render(
|
||||
'/information/table.twig',
|
||||
array(
|
||||
'labels' => array(
|
||||
'or' => __( 'Or...', 'wpcf' )
|
||||
),
|
||||
'thead' => $thead_views,
|
||||
'table' => $this->information
|
||||
)
|
||||
);
|
||||
|
||||
// Replace Placeholders
|
||||
Types_Helper_Placeholder::replace( $output_inner );
|
||||
|
||||
// no "echo" because we use meta-box as output
|
||||
$this->information->render( $output_inner );
|
||||
}
|
||||
|
||||
|
||||
protected function show_data_as_container_in_meta_box( $data_files ) {
|
||||
// add container for warning messages
|
||||
$this->information = new Types_Information_Container( 'types-informations-container' );
|
||||
// $this->information->cache_on_hook( 'edit_post' );
|
||||
|
||||
// add messages
|
||||
foreach( $data_files as $data_file ) {
|
||||
$this->load_data_to_table( $data_file );
|
||||
}
|
||||
|
||||
// outer box
|
||||
$output_meta_box = new Types_Helper_Output_Meta_Box();
|
||||
$output_meta_box->set_id( $this->information->get_id() );
|
||||
$output_meta_box->set_title( __( 'Front-end Display', 'wpcf' ) );
|
||||
// $output_meta_box->set_css_class( 'types-table-in-meta-box' );
|
||||
|
||||
$this->information->set_output_container( $output_meta_box );
|
||||
|
||||
$output_inner = $this->twig->render(
|
||||
'/information/single.twig',
|
||||
array(
|
||||
'icon' => 'dashicons dashicons-warning',
|
||||
'information' => $this->information
|
||||
)
|
||||
);
|
||||
|
||||
// Replace Placeholders
|
||||
Types_Helper_Placeholder::replace( $output_inner );
|
||||
|
||||
// no "echo" because we use meta-box as output
|
||||
$this->information->render( $output_inner );
|
||||
}
|
||||
|
||||
protected function load_data_to_table( $path ) {
|
||||
$data = require( $path );
|
||||
|
||||
foreach( $data as $msg_id => $msg_data ) {
|
||||
$msg = new Types_Information_Message();
|
||||
$msg_data['id'] = $msg_id;
|
||||
$msg->data_import( $msg_data );
|
||||
$this->information->add_message( $msg );
|
||||
}
|
||||
}
|
||||
|
||||
protected function thead_views_template_archive_views_forms() {
|
||||
|
||||
$thead_data = require( TYPES_DATA . '/information/table/question-marks.php' );
|
||||
$views = array();
|
||||
|
||||
$post_type = Types_Helper_Condition::get_post_type();
|
||||
|
||||
$allowed_columns = apply_filters( 'types_information_table_columns', array_fill_keys( array( 'template', 'archive', 'views', 'forms' ), '' ), $post_type->name );
|
||||
|
||||
foreach( $thead_data as $key => $column ) {
|
||||
if( ! array_key_exists( $key, $allowed_columns ) )
|
||||
unset( $thead_data[$key] );
|
||||
}
|
||||
|
||||
foreach( $thead_data as $data ) {
|
||||
$views[] = $this->twig->render(
|
||||
'/information/table/thead-cell.twig',
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
return $views;
|
||||
}
|
||||
|
||||
protected function prepare_table_in_meta_box() {
|
||||
// add dashboard
|
||||
$this->information = new Types_Information_Table( 'types-information-table' );
|
||||
|
||||
// save on edit post
|
||||
//$this->information->cache_on_hook( 'edit_post' );
|
||||
|
||||
// we want to display dashboard in a meta-box
|
||||
$output_meta_box = new Types_Helper_Output_Meta_Box();
|
||||
$output_meta_box->set_id( $this->information->get_id() );
|
||||
$output_meta_box->set_title( __( 'Front-end Display', 'wpcf' ) );
|
||||
$output_meta_box->set_css_class( 'types-table-in-meta-box' );
|
||||
|
||||
$this->information->set_output_container( $output_meta_box );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any embedded plugin is running.
|
||||
*
|
||||
* @todo Would be better placed in a helper.
|
||||
* @return bool
|
||||
*/
|
||||
protected function embedded_plugin_running() {
|
||||
|
||||
// check Layouts
|
||||
if( defined( 'WPDDL_EMBEDDED' ) )
|
||||
return true;
|
||||
|
||||
// check CRED
|
||||
if( defined( 'CRED_FE_VERSION' ) && class_exists('CRED_Admin') === false )
|
||||
return true;
|
||||
|
||||
// check Views
|
||||
if( defined( 'WPV_VERSION' ) ) {
|
||||
global $WP_Views;
|
||||
|
||||
if( is_object( $WP_Views ) && method_exists( $WP_Views, 'is_embedded' ))
|
||||
return $WP_Views->is_embedded();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Divi interoperability handler.
|
||||
*
|
||||
* @since 2.2.7
|
||||
*/
|
||||
class Types_Interop_Handler_Divi implements Types_Interop_Handler_Interface {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function initialize() {
|
||||
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
// Not giving away the instance on purpose.
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
private function __construct() {
|
||||
|
||||
// admin_enqueue_scripts is too late and init is too early ($typenow is not populated at that time).
|
||||
// Actually, we need to load with even earlier priority because Types already enqueues things
|
||||
// at load-post.php.
|
||||
add_action( 'load-post.php', array( $this, 'fix_validation_method_extension_dependency' ), 8 );
|
||||
add_action( 'load-post-new.php', array( $this, 'fix_validation_method_extension_dependency' ), 8 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fix a compatibility issue that happens on the Edit Post page.
|
||||
*
|
||||
* Implemented for Divi 3.0.29.
|
||||
*
|
||||
* Types is extending the jQuery UI Validation plugin with some additional validation rules,
|
||||
* some of which are used for custom field validation.
|
||||
*
|
||||
* The actual problem is that Divi is including the jQuery UI Validation plugin with a different
|
||||
* script handler, 'validation', which was overwriting the instance enqueued by Types, and thus
|
||||
* removing the additional validation rules.
|
||||
*
|
||||
* By registering the script with additional validation rules with a dependency on the Divi's
|
||||
* jQuery UI Validation plugin instance, we avoid this issue.
|
||||
*
|
||||
* A more straightforward solution might be changing the script handler to 'validation'
|
||||
* but that is a way too generic name and might cause issues elsewhere.
|
||||
*
|
||||
* Here, we're copying the logic of Divi's et_pb_admin_scripts_styles() and
|
||||
* re-register the script only if Divi is about to enqueue its jQuery UI Validation plugin.
|
||||
*
|
||||
* @since 2.2.7
|
||||
*/
|
||||
public function fix_validation_method_extension_dependency() {
|
||||
|
||||
if ( ! function_exists( 'et_builder_get_builder_post_types' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_types = et_builder_get_builder_post_types();
|
||||
|
||||
global $typenow;
|
||||
|
||||
if ( ! isset( $typenow ) || ! in_array( $typenow, $post_types ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we know that Divi is about to enqueue its jQuery UI Validation plugin.
|
||||
|
||||
wp_deregister_script( Types_Asset_Manager::SCRIPT_ADDITIONAL_VALIDATION_RULES );
|
||||
|
||||
$asset_manager = Types_Asset_Manager::get_instance();
|
||||
|
||||
wp_register_script(
|
||||
Types_Asset_Manager::SCRIPT_ADDITIONAL_VALIDATION_RULES,
|
||||
$asset_manager->get_additional_validation_script_url(),
|
||||
// add another dependency
|
||||
array( 'jquery', 'validation', Types_Asset_Manager::SCRIPT_JQUERY_UI_VALIDATION ),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* The7 theme interoperability handler.
|
||||
*
|
||||
* @since 2.2.16
|
||||
*/
|
||||
class Types_Interop_Handler_The7 implements Types_Interop_Handler_Interface {
|
||||
|
||||
/** @var Types_Interop_Handler_The7 */
|
||||
private static $instance;
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the interop handler.
|
||||
*/
|
||||
public static function initialize() {
|
||||
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
self::$instance->add_hooks();
|
||||
}
|
||||
|
||||
// Not giving away the instance on purpose.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hook to the event of rendering the legacy editor code, which happens just before
|
||||
* enqueuing assets.
|
||||
*/
|
||||
public function add_hooks() {
|
||||
add_action( 'types_leagacy_editor_callback_init', array( $this, 'remove_presscore_hooks' ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fix a compatibility issue caused, simply put, by our own terrible mess.
|
||||
*
|
||||
* The issue was visible when activating The7 theme, Views and Types, on the Edit Content Template page (for example).
|
||||
* When trying to add a Types field, the AJAX call to render the dialog markup has failed due to a fatal error.
|
||||
* The result was that the dialog never opened and the user was left with the grey overlay and no error message.
|
||||
*
|
||||
* The fatal error was caused by the fact that the legacy code in Types, namely in embedded/includes/ajax/admin-header.php
|
||||
* is running do_action( 'admin_enqueue_scripts', $hook_suffix ); outside of the context of the
|
||||
* standard admin page loading mechanism.
|
||||
*
|
||||
* That causes problems in The7_Demo_Content_Admin::enqueue_scripts() (which is hooked even during this
|
||||
* non-standard procedure): It accesses the global $tgmpa variable which is assumed to be
|
||||
* an instance of The7_TGMPA but for some reason, it's never initialized.
|
||||
*
|
||||
* The workaround is also extremely ugly: We intercept the AJAX call that renders the dialog markup and check
|
||||
* all admin_enqueue_scripts hooks. If its callback has a prefix coming from The7 theme, we'll remove the action.
|
||||
*
|
||||
* It is safe because we're targeting only a very specific scenario, where the theme's admin assets
|
||||
* aren't needed at all.
|
||||
*
|
||||
* This can be removed when the dialog is finally refactored into something sensible.
|
||||
*
|
||||
* @since 2.2.16
|
||||
*/
|
||||
public function remove_presscore_hooks() {
|
||||
if ( toolset_getget( 'action' ) === 'wpcf_ajax' && toolset_getget( 'wpcf_action' ) === 'editor_callback' ) {
|
||||
global $wp_filter;
|
||||
/** @var WP_Hook $admin_enqueue_script_hooks */
|
||||
$admin_enqueue_script_hooks = toolset_getarr( $wp_filter, 'admin_enqueue_scripts', array() );
|
||||
|
||||
foreach ( $admin_enqueue_script_hooks->callbacks as $priority => $callbacks_for_priority ) {
|
||||
foreach ( $callbacks_for_priority as $callback_id => $callback ) {
|
||||
$function = $callback['function'];
|
||||
|
||||
$the7_string_prefix = 'presscore_';
|
||||
$is_the7_string_callback = ( is_string( $function ) && substr( $function, 0, strlen( $the7_string_prefix ) ) === $the7_string_prefix );
|
||||
|
||||
$the7_class_prefix = 'The7_';
|
||||
$is_the7_class_callback = (
|
||||
is_array( $function )
|
||||
&& count( $function ) === 2
|
||||
&& substr( get_class( $function[0] ), 0, strlen( $the7_class_prefix ) ) === $the7_class_prefix
|
||||
);
|
||||
|
||||
if ( $is_the7_class_callback || $is_the7_string_callback ) {
|
||||
remove_action( 'admin_enqueue_scripts', $function, $priority );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Use Any Font interoperability handler.
|
||||
*
|
||||
* @link https://wordpress.org/plugins/use-any-font/
|
||||
*
|
||||
* @since 2.2.9
|
||||
*/
|
||||
class Types_Interop_Handler_Use_Any_Font implements Types_Interop_Handler_Interface {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function initialize() {
|
||||
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
// Not giving away the instance on purpose.
|
||||
|
||||
}
|
||||
|
||||
|
||||
private function __clone() {
|
||||
}
|
||||
|
||||
|
||||
private function __construct() {
|
||||
$this->maybe_unregister_uaf_assets();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fix a compatibility issue with conflicting JS assets.
|
||||
*
|
||||
* Implemented for Use Any Font 4.6.
|
||||
*
|
||||
* On Edit Post Type page, UAF enqueues its own instance of jQuery UI Validation plugin which overwrites the one
|
||||
* from Types, with added additional validation rules.
|
||||
*
|
||||
* Turns out, UAF enqueues everything everywhere without care although it has only a single admin page.
|
||||
* In general, it has very bad coding practices (unprefixed function names, etc.)
|
||||
*
|
||||
* Here, we do what UAF should do on its own: Check if we're on its settings page and if
|
||||
* we're not, avoid loading its assets.
|
||||
*
|
||||
* @since 2.2.9
|
||||
*/
|
||||
function maybe_unregister_uaf_assets() {
|
||||
$main_controller = Types_Main::get_instance();
|
||||
$is_uaf_settings_page = (
|
||||
$main_controller->get_plugin_mode() === Types_Main::MODE_ADMIN && wpcf_getget( 'page' ) === 'uaf_settings_page'
|
||||
);
|
||||
|
||||
if ( ! $is_uaf_settings_page ) {
|
||||
remove_action( 'admin_print_scripts', 'adminjslibs' );
|
||||
remove_action( 'admin_print_styles', 'adminCsslibs' );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* WPML interoperability handler.
|
||||
*
|
||||
* WIP - this stub is to be filled with everything WPML-related.
|
||||
* Look into: vendor/toolset/types/embedded/includes/wpml.php
|
||||
*
|
||||
* @since 2.2.9
|
||||
*/
|
||||
class Types_Interop_Handler_Wpml implements Types_Interop_Handler_Interface {
|
||||
|
||||
|
||||
private static $instance;
|
||||
|
||||
private function __construct() { }
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
public static function initialize() {
|
||||
self::get_instance();
|
||||
}
|
||||
|
||||
|
||||
public static function get_instance() {
|
||||
if( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the current language is the default one.
|
||||
*
|
||||
* The result is cached for better performance.
|
||||
*
|
||||
* @return bool
|
||||
* @since 2.2.9
|
||||
*/
|
||||
public function is_current_language_default() {
|
||||
static $result = null;
|
||||
|
||||
if( null === $result ) {
|
||||
$current_language = apply_filters( 'wpml_current_language', null );
|
||||
$default_language = apply_filters( 'wpml_default_language', null );
|
||||
$result = ( $current_language === $default_language );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get translation of string.
|
||||
*
|
||||
* @param string $string The original string value to translate
|
||||
* @param string $string_name String name
|
||||
* @param string $domain String domain
|
||||
*
|
||||
* @link https://wpml.org/wpml-hook/wpml_translate_single_string/
|
||||
*
|
||||
* @return false|string Translated string or false if no such string is registered.
|
||||
* @since 2.2.9
|
||||
*/
|
||||
public function get_translation( $string, $string_name, $domain ) {
|
||||
|
||||
// check if translation exists
|
||||
$is_registered = apply_filters(
|
||||
'wpml_string_id',
|
||||
null,
|
||||
array(
|
||||
'context' => $domain,
|
||||
'name' => $string_name
|
||||
)
|
||||
);
|
||||
|
||||
if ( $is_registered === null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// string is registered, return translation
|
||||
return apply_filters(
|
||||
'wpml_translate_single_string',
|
||||
$string,
|
||||
$domain,
|
||||
$string_name
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Interface Types_Interop_Handler_Interface
|
||||
*
|
||||
* See Types_Interop_Mediator for details.
|
||||
*
|
||||
* @since 2.2.7
|
||||
*/
|
||||
interface Types_Interop_Handler_Interface {
|
||||
|
||||
public static function initialize();
|
||||
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Provide interoperability with other plugins or themes when needed.
|
||||
*
|
||||
* Each plugin or a theme that Types needs to (actively) support should
|
||||
* have a dedicated "interoperability handler" that, when initialized,
|
||||
* will provide such support (preferably via actions and filters).
|
||||
*
|
||||
* Having everything located in one class will make it very easy to
|
||||
* handle and implement future compatibility issues and it will
|
||||
* reduce memory usage by loading the code only when needed.
|
||||
*
|
||||
* Use this as a singleton in production code.
|
||||
*
|
||||
* @since 2.2.7
|
||||
*/
|
||||
class Types_Interop_Mediator {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function initialize() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
self::$instance->initialize_interop_handlers();
|
||||
}
|
||||
|
||||
// Not giving away the instance on purpose
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get definitions of all interop handlers.
|
||||
*
|
||||
* Each one has a method for checking whether the handler is needed
|
||||
* and a name - there must be a corresponding class Types_Interop_Handler_{$name}
|
||||
* implementing the Types_Interop_Handler_Interface.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.2.7
|
||||
*/
|
||||
private function get_interop_handler_definitions() {
|
||||
|
||||
$interop_handlers = array(
|
||||
array(
|
||||
'is_needed' => array( $this, 'is_wpml_active' ),
|
||||
'class_name' => 'Wpml'
|
||||
),
|
||||
array(
|
||||
'is_needed' => array( $this, 'is_divi_active' ),
|
||||
'class_name' => 'Divi'
|
||||
),
|
||||
array(
|
||||
'is_needed' => array( $this, 'is_use_any_font_active' ),
|
||||
'class_name' => 'Use_Any_Font'
|
||||
),
|
||||
array(
|
||||
'is_needed' => array( $this, 'is_the7_active' ),
|
||||
'class_name' => 'The7'
|
||||
),
|
||||
);
|
||||
|
||||
return $interop_handlers;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load and initialize interop handlers if the relevant plugin/theme is active.
|
||||
*
|
||||
* @since 2.2.7
|
||||
*/
|
||||
public function initialize_interop_handlers() {
|
||||
|
||||
/**
|
||||
* types_get_interop_handler_definitions
|
||||
*
|
||||
* Allows for adjusting interop handlers. See Types_Interop_Mediator::get_interop_handler_definitions() for details.
|
||||
*
|
||||
* @since 2.2.17
|
||||
*/
|
||||
$interop_handlers = apply_filters( 'types_get_interop_handler_definitions', $this->get_interop_handler_definitions() );
|
||||
|
||||
foreach ( $interop_handlers as $handler_definition ) {
|
||||
$is_needed = call_user_func( $handler_definition['is_needed'] );
|
||||
|
||||
if ( $is_needed ) {
|
||||
$handler_class_name = 'Types_Interop_Handler_' . $handler_definition['class_name'];
|
||||
call_user_func( $handler_class_name . '::initialize' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether WPML is active and configured.
|
||||
*
|
||||
* @return bool
|
||||
* @since 2.2.7
|
||||
*/
|
||||
protected function is_wpml_active() {
|
||||
|
||||
global $sitepress;
|
||||
$is_wpml_active = (
|
||||
defined( 'ICL_SITEPRESS_VERSION' )
|
||||
&& ! ICL_PLUGIN_INACTIVE
|
||||
&& ! is_null( $sitepress )
|
||||
&& class_exists( 'SitePress' )
|
||||
);
|
||||
|
||||
return $is_wpml_active;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the Divi theme is loaded.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_divi_active() {
|
||||
return function_exists( 'et_setup_theme' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the The7 theme is loaded.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_the7_active() {
|
||||
return ( 'the7' === $this->get_parent_theme_slug() );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the Use Any Font plugin is loaded.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_use_any_font_active() {
|
||||
return function_exists( 'uaf_activate' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a "slugized" theme name.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.2.16
|
||||
*/
|
||||
private function get_parent_theme_slug() {
|
||||
|
||||
/**
|
||||
* @var WP_Theme|null $theme It should be WP_Theme but experience tells us that sometimes the theme
|
||||
* manages to send an invalid value our way.
|
||||
*/
|
||||
$theme = wp_get_theme();
|
||||
|
||||
if( ! $theme instanceof WP_Theme ) {
|
||||
// Something went wrong but we'll try to recover.
|
||||
$theme_name = $this->get_theme_name_from_stylesheet();
|
||||
} elseif ( is_child_theme() ) {
|
||||
|
||||
$parent_theme = $theme->parent();
|
||||
|
||||
// Because is_child_theme() can return true while $theme->parent() still returns false, oh dear god.
|
||||
if( ! $parent_theme instanceof WP_Theme ) {
|
||||
$theme_name = $this->get_theme_name_from_stylesheet();
|
||||
} else {
|
||||
$theme_name = $parent_theme->get( 'Name' );
|
||||
}
|
||||
} else {
|
||||
$theme_name = $theme->get( 'Name' );
|
||||
}
|
||||
|
||||
// Handle $theme->get() returning false when the Name header is not set.
|
||||
if( false === $theme_name ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$slug = str_replace( '-', '_', sanitize_title( $theme_name ) );
|
||||
|
||||
return $slug;
|
||||
}
|
||||
|
||||
|
||||
private function get_theme_name_from_stylesheet() {
|
||||
$theme_name = '';
|
||||
|
||||
$stylesheet = get_stylesheet();
|
||||
if( is_string( $stylesheet ) && ! empty( $stylesheet ) ) {
|
||||
$theme_name = $stylesheet;
|
||||
}
|
||||
|
||||
return $theme_name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Main Types controller.
|
||||
*
|
||||
* Determines if we're in admin or front-end mode or if an AJAX call is being performed. Handles tasks that are common
|
||||
* to all three modes, if there are any.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Main {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public static function initialize() {
|
||||
self::get_instance();
|
||||
}
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
private function __construct() {
|
||||
|
||||
add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ), 10 );
|
||||
add_action( 'init', array( $this, 'on_init' ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Determine in which mode we are and initialize the right dedicated controller.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function on_init() {
|
||||
if( is_admin() ) {
|
||||
if( defined( 'DOING_AJAX' ) ) {
|
||||
$this->mode = self::MODE_AJAX;
|
||||
Types_Ajax::initialize();
|
||||
} else {
|
||||
$this->mode = self::MODE_ADMIN;
|
||||
Types_Admin::initialize();
|
||||
}
|
||||
} else {
|
||||
$this->mode = self::MODE_FRONTEND;
|
||||
Types_Frontend::initialize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var string One of the MODE_* constants.
|
||||
*/
|
||||
private $mode = self::MODE_UNDEFINED;
|
||||
|
||||
const MODE_UNDEFINED = '';
|
||||
const MODE_AJAX = 'ajax';
|
||||
const MODE_ADMIN = 'admin';
|
||||
const MODE_FRONTEND = 'frontend';
|
||||
|
||||
/**
|
||||
* Get current plugin mode.
|
||||
*
|
||||
* Possible values are:
|
||||
* - MODE_UNDEFINED before the main controller initialization is completed
|
||||
* - MODE_AJAX when doing an AJAX request
|
||||
* - MODE_ADMIN when showing a WP admin page
|
||||
* - MODE_FRONTEND when rendering a frontend page
|
||||
*
|
||||
* @return string
|
||||
* @since 2.1
|
||||
*/
|
||||
public function get_plugin_mode() {
|
||||
return $this->mode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set current plugin mode.
|
||||
*
|
||||
* @param string $new_mode the new plugin mode
|
||||
* @return bool TRUE if set is succesfully done, FALSE otherwise
|
||||
* @since 2.2
|
||||
*/
|
||||
public function set_plugin_mode( $new_mode = self::MODE_UNDEFINED ) {
|
||||
if ( !in_array( $new_mode, array( self::MODE_UNDEFINED, self::MODE_AJAX, self::MODE_ADMIN, self::MODE_FRONTEND ) ) ){
|
||||
return false;
|
||||
}
|
||||
$this->mode = $new_mode;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether a WP admin page is being loaded.
|
||||
*
|
||||
* Note that the behaviour differs from the native is_admin() which will return true also for AJAX requests.
|
||||
*
|
||||
* @return bool
|
||||
* @since 2.1
|
||||
*/
|
||||
public function is_admin() {
|
||||
return ( $this->get_plugin_mode() == self::MODE_ADMIN );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Early loading actions.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function after_setup_theme() {
|
||||
|
||||
// Initialize the Toolset Common library
|
||||
Toolset_Common_Bootstrap::get_instance();
|
||||
|
||||
$this->setup_autoloader();
|
||||
|
||||
// If an AJAX callback handler needs other assets, it should initialize the asset manager by itself.
|
||||
if( $this->get_plugin_mode() != self::MODE_AJAX ) {
|
||||
Types_Assets::get_instance()->initialize_scripts_and_styles();
|
||||
}
|
||||
|
||||
// Handle embedded plugin mode
|
||||
Types_Embedded::initialize();
|
||||
|
||||
Types_Api::initialize();
|
||||
|
||||
Types_Interop_Mediator::initialize();
|
||||
}
|
||||
|
||||
|
||||
private function setup_autoloader() {
|
||||
|
||||
// It is possible to regenerate the classmap with Zend framework.
|
||||
//
|
||||
// See the "recreate_classmap.sh" script in the plugin root directory.
|
||||
$classmap = include( TYPES_ABSPATH . '/application/autoload_classmap.php' );
|
||||
|
||||
// Use Toolset_Common_Autoloader
|
||||
do_action( 'toolset_register_classmap', $classmap );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* In some cases, it may not be clear what legacy files are includes and what aren't.
|
||||
*
|
||||
* This method should make sure all is covered (add files when needed). Use only when necessary.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function require_legacy_functions() {
|
||||
require_once WPCF_INC_ABSPATH . '/fields.php';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Abstract admin page controller.
|
||||
*
|
||||
* All page controllers must inherit from this one.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class Types_Page_Abstract {
|
||||
|
||||
|
||||
/** @var bool Whether to disable heartbeat. Default is true (disable). */
|
||||
protected $disable_heartbeat = true;
|
||||
|
||||
|
||||
/**
|
||||
* Prepare the page controller for displaying a page.
|
||||
*
|
||||
* This should be the first time where any kind of preparation happens (it shouldn't happen during
|
||||
* instantiating the class).
|
||||
*
|
||||
* By default, this disables the WordPress Heartbeat API in order to save resources and speed up AJAX calls.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function prepare() {
|
||||
|
||||
if ( $this->disable_heartbeat ) {
|
||||
wp_deregister_script( 'heartbeat' );
|
||||
wp_register_script( 'heartbeat', false );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Title to be displayed on the menu as well in the page title.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract public function get_title();
|
||||
|
||||
|
||||
/**
|
||||
* Callback for the page rendering action.
|
||||
*
|
||||
* @return callable
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract public function get_render_callback();
|
||||
|
||||
|
||||
/**
|
||||
* Callback for the page load action (load-{$hook}).
|
||||
*
|
||||
* @return null|callable Optional.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_load_callback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Page name slug.
|
||||
*
|
||||
* Should be taken directly from constants in Types_Admin_Menu.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract public function get_page_name();
|
||||
|
||||
|
||||
/**
|
||||
* User capability required to display the submenu item and access the page.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract public function get_required_capability();
|
||||
|
||||
}
|
||||
@@ -1,528 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* "Dashboard" page controller.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
final class Types_Page_Dashboard extends Types_Page_Abstract {
|
||||
|
||||
protected $dashboard;
|
||||
protected $twig;
|
||||
|
||||
protected $table_toolset = false;
|
||||
protected $table_3rd = false;
|
||||
protected $table_wordpress;
|
||||
|
||||
protected $types_by_toolset;
|
||||
protected $types_by_3rd;
|
||||
protected $types_by_wordpress;
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
add_filter( 'toolset_filter_register_menu_pages', array( Types_Page_Dashboard::$instance, 'register_page_dashboard_in_menu' ), 1000 );
|
||||
add_action( 'load-toplevel_page_toolset-dashboard', array( Types_Page_Dashboard::$instance, 'on_load_page' ) );
|
||||
add_filter( 'set-screen-option', array( Types_Page_Dashboard::$instance, 'screen_settings_save') , 11, 3);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() { }
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
public function on_load_page() {
|
||||
add_filter( 'screen_settings', array( Types_Page_Dashboard::$instance, 'screen_settings' ), 10, 2 );
|
||||
add_action( 'admin_enqueue_scripts', array( Types_Page_Dashboard::$instance, 'on_admin_enqueue_scripts' ) );
|
||||
|
||||
$this->help_information();
|
||||
}
|
||||
|
||||
public function register_page_dashboard_in_menu( $pages ) {
|
||||
array_unshift( $pages, array(
|
||||
'slug' => 'toolset-dashboard',
|
||||
'menu_title' => $this->get_menu_title(),
|
||||
'page_title' => $this->get_title(),
|
||||
'callback' => $this->get_render_callback()
|
||||
) );
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
return __( 'Toolset Dashboard', 'wpcf' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return string
|
||||
*/
|
||||
public function get_menu_title() {
|
||||
return __( 'Dashboard', 'wpcf' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return callable
|
||||
*/
|
||||
public function get_render_callback() {
|
||||
return array( $this, 'render_page' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return string
|
||||
*/
|
||||
public function get_page_name() {
|
||||
return Types_Admin_Menu::PAGE_NAME_DASHBOARD;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return string
|
||||
*/
|
||||
public function get_required_capability() {
|
||||
return 'manage_options'; // todo better role/cap handling
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return callable
|
||||
*/
|
||||
public function get_load_callback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function on_admin_enqueue_scripts() {
|
||||
$main_handle = 'types-page-dashboard-main';
|
||||
|
||||
// script
|
||||
wp_enqueue_script(
|
||||
$main_handle,
|
||||
TYPES_RELPATH . '/public/js/information.js',
|
||||
array( 'jquery-ui-dialog', 'wp-pointer' ),
|
||||
TYPES_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
// style
|
||||
wp_enqueue_style(
|
||||
$main_handle,
|
||||
TYPES_RELPATH . '/public/css/information.css',
|
||||
array( 'wp-jquery-ui-dialog', 'wp-pointer' ),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
// load icons
|
||||
wp_enqueue_style(
|
||||
'onthegosystems-icons',
|
||||
WPCF_EMBEDDED_TOOLSET_RELPATH . '/onthego-resources/onthegosystems-icons/css/onthegosystems-icons.css',
|
||||
array(),
|
||||
TYPES_VERSION
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function get_twig() {
|
||||
if( $this->twig == null )
|
||||
$this->twig = new Types_Helper_Twig();
|
||||
|
||||
return $this->twig;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public function render_page() {
|
||||
|
||||
$context = $this->build_page_context();
|
||||
|
||||
echo $this->get_twig()->render( '/page/dashboard/main.twig', $context );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the context for main page template.
|
||||
*
|
||||
* @return array Page context. See the main page template for details.
|
||||
* @since 2.1
|
||||
*/
|
||||
private function build_page_context() {
|
||||
$this->get_dashboard();
|
||||
|
||||
$context = array(
|
||||
'page' => self::get_instance(),
|
||||
'table_toolset' => $this->table_toolset,
|
||||
'table_3rd' => $this->table_3rd,
|
||||
'table_wordpress' => $this->table_wordpress,
|
||||
'labels' => array(
|
||||
'create_type' => __( 'Add new post type', 'wpcf' ),
|
||||
'msg_no_custom_post_types' =>
|
||||
__( 'To get started, create your first custom type. Then, you will be able to add fields and taxonomy and design how it displays.', 'wpcf' )
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Types by Toolset
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_types_by_toolset() {
|
||||
if( $this->types_by_toolset !== null )
|
||||
return $this->types_by_toolset;
|
||||
|
||||
$post_type_option = new Types_Utils_Post_Type_Option();
|
||||
|
||||
$cpts_raw = ! isset( $_GET['toolset-dashboard-simulate-no-custom-post-types'] )
|
||||
? $post_type_option->get_post_types()
|
||||
: array();
|
||||
|
||||
// remove buildin types
|
||||
$cpts_raw = array_diff_key( $cpts_raw, $this->get_types_by_wordpress() );
|
||||
|
||||
$cpts = array();
|
||||
|
||||
foreach( $cpts_raw as $cpt_raw ) {
|
||||
$post_type = new Types_Post_Type( $cpt_raw['slug'] );
|
||||
// only use active post types
|
||||
if( isset( $post_type->name ) )
|
||||
$cpts[$cpt_raw['slug']] = $post_type;
|
||||
}
|
||||
|
||||
uasort( $cpts, array( $this, 'sort_post_types_by_name' ) );
|
||||
|
||||
$this->types_by_toolset = $cpts;
|
||||
return $this->types_by_toolset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Types by WordPress
|
||||
* @return array
|
||||
*/
|
||||
private function get_types_by_wordpress() {
|
||||
if( $this->types_by_wordpress !== null )
|
||||
return $this->types_by_wordpress;
|
||||
|
||||
$cpts_raw = array(
|
||||
'post' => array(
|
||||
'slug' => 'post',
|
||||
'_buildin' => 1
|
||||
),
|
||||
'page' => array(
|
||||
'slug' => 'page',
|
||||
'_buildin' => 1
|
||||
),
|
||||
'attachment' => array(
|
||||
'slug' => 'attachment',
|
||||
'_buildin' => 1
|
||||
),
|
||||
);
|
||||
|
||||
$cpts = array();
|
||||
foreach( $cpts_raw as $cpt_raw ) {
|
||||
$post_type = new Types_Post_Type( $cpt_raw['slug'] );
|
||||
// only use active post types
|
||||
if( isset( $post_type->name ) )
|
||||
$cpts[$cpt_raw['slug']] = $post_type;
|
||||
}
|
||||
|
||||
uasort( $cpts, array( $this, 'sort_post_types_by_name' ) );
|
||||
$this->types_by_wordpress = $cpts;
|
||||
|
||||
return $this->types_by_wordpress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Types by 3rd (by themes/plugins)
|
||||
* @return array
|
||||
*/
|
||||
private function get_types_by_3rd() {
|
||||
if( $this->types_by_3rd !== null )
|
||||
return $this->types_by_3rd;
|
||||
|
||||
$cpts_raw = get_post_types( array( 'public' => true ) );
|
||||
$cpts = array();
|
||||
foreach( $cpts_raw as $cpt_slug => $cpt_raw ) {
|
||||
$post_type = new Types_Post_Type( $cpt_slug );
|
||||
// only use active post types
|
||||
if( isset( $post_type->name ) )
|
||||
$cpts[$cpt_slug] = $post_type;
|
||||
}
|
||||
|
||||
$cpts = array_diff_key( $cpts, $this->get_types_by_wordpress(), $this->get_types_by_toolset() );
|
||||
|
||||
uasort( $cpts, array( $this, 'sort_post_types_by_name' ) );
|
||||
$this->types_by_3rd = $cpts;
|
||||
|
||||
return $this->types_by_3rd;
|
||||
}
|
||||
|
||||
private function sort_post_types_by_name( $a, $b ) {
|
||||
return strcasecmp( $a->name, $b->name ) > 0 ? true : false;
|
||||
}
|
||||
|
||||
private function get_post_types_filtered_by_screen_options( $cpts = false ) {
|
||||
if( $cpts === false )
|
||||
$cpts = array_merge( $this->get_types_by_toolset(), $this->get_types_by_wordpress(), $this->get_types_by_3rd() );
|
||||
|
||||
$cpts_filtered = array();
|
||||
|
||||
$user = get_current_user_id();
|
||||
$user_settings = get_user_meta($user, 'toolset_dashboard_screen_post_types', true );
|
||||
|
||||
// no user settings yet
|
||||
if( empty( $user_settings ) ) {
|
||||
|
||||
// by default no media
|
||||
if( isset( $cpts['attachment'] ) ) {
|
||||
unset( $cpts['attachment'] );
|
||||
}
|
||||
|
||||
|
||||
$cpts_filtered = $cpts;
|
||||
} else {
|
||||
foreach( $cpts as $post_type => $cpt ) {
|
||||
// default for post/page/media is unchecked
|
||||
if( ! isset( $user_settings[$post_type] )
|
||||
&& ( $post_type == 'post' || $post_type == 'page' || $post_type == 'attachment' )
|
||||
) continue;
|
||||
|
||||
if( !empty( $user_settings ) ) {
|
||||
|
||||
if( ! isset( $user_settings[$post_type] ) // default = checked
|
||||
|| $user_settings[$post_type] == 'on' ) // checked by user
|
||||
$cpts_filtered[$post_type] = $cpt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $cpts_filtered;
|
||||
}
|
||||
|
||||
private function get_dashboard() {
|
||||
// Types by Toolset
|
||||
$post_types = $this->get_post_types_filtered_by_screen_options( $this->get_types_by_toolset() );
|
||||
|
||||
if( ! empty( $post_types ) )
|
||||
$this->table_toolset = $this->get_dashboard_types_table(
|
||||
$post_types,
|
||||
__( 'Custom post types that you created with Toolset', 'wpcf' )
|
||||
);
|
||||
|
||||
|
||||
// Types by 3rd
|
||||
$post_types = $this->get_post_types_filtered_by_screen_options( $this->get_types_by_3rd() );
|
||||
|
||||
if( ! empty( $post_types ) )
|
||||
$this->table_3rd = $this->get_dashboard_types_table(
|
||||
$post_types,
|
||||
__( 'Custom post types created by the theme and other plugins', 'wpcf' ),
|
||||
false
|
||||
);
|
||||
|
||||
|
||||
// Types by Wordpress
|
||||
$post_types = $this->get_post_types_filtered_by_screen_options( $this->get_types_by_wordpress() );
|
||||
|
||||
if( ! empty( $post_types ) )
|
||||
$this->table_wordpress = $this->get_dashboard_types_table(
|
||||
$post_types,
|
||||
__( 'Built-in post types created by WordPress', 'wpcf' ),
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function load_data_to_table( $path, &$info ) {
|
||||
$data = require( $path );
|
||||
|
||||
foreach( $data as $msg_id => $msg_data ) {
|
||||
$msg = new Types_Information_Message();
|
||||
$msg_data['id'] = $msg_id;
|
||||
$msg->data_import( $msg_data );
|
||||
$info->add_message( $msg );
|
||||
}
|
||||
}
|
||||
|
||||
public function screen_settings( $status, $args ) {
|
||||
$return = $status;
|
||||
|
||||
$cpts_filtered = $this->get_post_types_filtered_by_screen_options();
|
||||
|
||||
// Types by Toolset
|
||||
$cpts = $this->get_types_by_toolset();
|
||||
if( ! empty( $cpts ) ) {
|
||||
$string_legend = __( 'Custom post types that you created with Toolset', 'wpcf' );
|
||||
$return .= $this->screen_settings_fieldset( $cpts, $cpts_filtered, $string_legend );
|
||||
}
|
||||
|
||||
// Types by 3rd
|
||||
$cpts = $this->get_types_by_3rd();
|
||||
if( ! empty( $cpts ) ) {
|
||||
$string_legend = __( 'Custom post types created by the theme and other plugins', 'wpcf' );
|
||||
$return .= $this->screen_settings_fieldset( $cpts, $cpts_filtered, $string_legend );
|
||||
}
|
||||
|
||||
// Types by WordPress
|
||||
$cpts = $this->get_types_by_wordpress();
|
||||
$string_legend = __( 'Built-in post types created by WordPress', 'wpcf' );
|
||||
$return .= $this->screen_settings_fieldset( $cpts, $cpts_filtered, $string_legend );
|
||||
|
||||
$return .= get_submit_button( __( 'Apply' ), 'button button-primary', 'screen-options-apply', false );
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function screen_settings_fieldset( $cpts, $cpts_filtered, $legend ) {
|
||||
$string = '
|
||||
<fieldset>
|
||||
<legend>' . $legend . '</legend>
|
||||
<div class="metabox-prefs">
|
||||
<div><input type="hidden" name="wp_screen_options[option]" value="toolset_dashboard_screen_post_types" /></div>
|
||||
<div><input type="hidden" name="wp_screen_options[value]" value="yes" /></div>
|
||||
<div class="toolset-dashboard-screen-post-types">';
|
||||
foreach( $cpts as $cpt ) {
|
||||
$checked = isset( $cpts_filtered[$cpt->get_name()] ) ? ' checked="checked" ' : ' ';
|
||||
$string .= '<input type="hidden" value="off" name="toolset_dashboard_screen_post_types['.$cpt->get_name().']" />';
|
||||
$string .= '<label for="toolset-dashboard-screen-post-type-'.$cpt->get_name().'"><input type="checkbox"' . $checked . 'value="on" name="toolset_dashboard_screen_post_types['.$cpt->get_name().']" id="toolset-dashboard-screen-post-type-'.$cpt->get_name().'" /> '.$cpt->name.'</label>';
|
||||
}
|
||||
$string .= '</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<br class="clear">
|
||||
';
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public function screen_settings_save($status, $option, $value) {
|
||||
if ( 'toolset_dashboard_screen_post_types' == $option ) {
|
||||
if ( is_array( $_POST['toolset_dashboard_screen_post_types'] ) ) {
|
||||
$toolset_dashboard_screen_post_types = array();
|
||||
foreach( $_POST['toolset_dashboard_screen_post_types'] as $tdspt_key => $tdspt_value ) {
|
||||
$tdspt_key = sanitize_text_field( $tdspt_key );
|
||||
$tdspt_value = sanitize_text_field( $tdspt_value );
|
||||
$toolset_dashboard_screen_post_types[ $tdspt_key ] = $tdspt_value;
|
||||
}
|
||||
} else {
|
||||
$toolset_dashboard_screen_post_types = sanitize_text_field( $_POST['toolset_dashboard_screen_post_types'] );
|
||||
}
|
||||
$value = $toolset_dashboard_screen_post_types;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
private function help_information() {
|
||||
$title = __('Toolset Dashboard', 'wpcf');
|
||||
$help_content = $this->get_twig()->render(
|
||||
'/page/dashboard/help.twig',
|
||||
array( 'title' => $title )
|
||||
);
|
||||
|
||||
$screen = get_current_screen();
|
||||
$screen->add_help_tab(
|
||||
array(
|
||||
'id' => 'toolset-dashboard-information',
|
||||
'title' => $title,
|
||||
'content' => $help_content,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $post_types
|
||||
* @param $headline
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_dashboard_types_table( $post_types, $headline, $post_type_edit_link = true ) {
|
||||
// documentation urls
|
||||
$documentation_urls = include( TYPES_DATA . '/documentation-urls.php' );
|
||||
|
||||
// add links to use analytics
|
||||
Types_Helper_Url::add_urls( $documentation_urls );
|
||||
|
||||
// set analytics medium
|
||||
Types_Helper_Url::set_medium( 'dashboard' );
|
||||
|
||||
/* messages */
|
||||
$messages_files = array(
|
||||
TYPES_DATA . '/dashboard/table/template.php',
|
||||
TYPES_DATA . '/dashboard/table/archive.php',
|
||||
TYPES_DATA . '/dashboard/table/views.php',
|
||||
TYPES_DATA . '/dashboard/table/forms.php',
|
||||
);
|
||||
|
||||
// add dashboard
|
||||
$rows = '';
|
||||
|
||||
foreach( $post_types as $post_type ) {
|
||||
$info_post_type = new Types_Information_Table( 'types-information-table' );
|
||||
Types_Helper_Condition::set_post_type( $post_type->get_name() );
|
||||
Types_Helper_Placeholder::set_post_type( $post_type->get_name() );
|
||||
|
||||
foreach( $messages_files as $message_file ) {
|
||||
$this->load_data_to_table( $message_file, $info_post_type );
|
||||
}
|
||||
|
||||
$row = $this->get_twig()->render(
|
||||
'/page/dashboard/table/tbody-row.twig',
|
||||
array(
|
||||
'labels' => array(
|
||||
'or' => __( 'Or...', 'wpcf' ),
|
||||
'create_taxonomy' => __( 'Create taxonomy', 'wpcf' ),
|
||||
'create_field_group' => __( 'Create field group', 'wpcf' ),
|
||||
'no_archive_for' => __( 'No archive available for %s', 'wpcf' ),
|
||||
),
|
||||
'admin_url' => admin_url(),
|
||||
'post_type' => $post_type,
|
||||
'table' => $info_post_type,
|
||||
'post_type_edit_link' => $post_type_edit_link
|
||||
)
|
||||
);
|
||||
|
||||
Types_Helper_Placeholder::replace( $row );
|
||||
$rows .= $row;
|
||||
}
|
||||
|
||||
|
||||
// table view
|
||||
$data_thead = require( TYPES_DATA . '/dashboard/table/head.php' );
|
||||
$table = $this->get_twig()->render(
|
||||
'/page/dashboard/table.twig',
|
||||
array(
|
||||
'labels' => array(
|
||||
'headline' => $headline,
|
||||
'admin' => __( 'WordPress admin', 'wpcf' ),
|
||||
'frontend' => __( 'Front-end', 'wpcf' ),
|
||||
'or' => __( 'Or...', 'wpcf' ),
|
||||
),
|
||||
'admin_url' => admin_url(),
|
||||
'thead' => $data_thead,
|
||||
'rows' => $rows
|
||||
)
|
||||
);
|
||||
|
||||
return $table;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This controller extends all post edit pages
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Page_Extension_Edit_Post {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
$post = wpcf_admin_get_edited_post();
|
||||
$post_type = wpcf_admin_get_edited_post_type( $post );
|
||||
|
||||
// if no post or no page
|
||||
if( $post_type != 'post' && $post_type != 'page' ) {
|
||||
$post_type_option = new Types_Utils_Post_Type_Option();
|
||||
$custom_types = $post_type_option->get_post_types();
|
||||
|
||||
// abort if also no custom post type of types
|
||||
if( ! array_key_exists( $post_type, $custom_types ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->prepare();
|
||||
}
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
public function prepare() {
|
||||
// documentation urls
|
||||
Types_Helper_Url::load_documentation_urls();
|
||||
|
||||
// set analytics medium
|
||||
Types_Helper_Url::set_medium( 'post_editor' );
|
||||
|
||||
// add information
|
||||
$this->prepare_information();
|
||||
|
||||
// @todo load scripts
|
||||
if( function_exists( 'wpcf_edit_post_screen_scripts' ) )
|
||||
wpcf_edit_post_screen_scripts();
|
||||
}
|
||||
|
||||
private function prepare_information() {
|
||||
$setting = new Types_Setting_Preset_Information_Table();
|
||||
|
||||
if( ! $setting->get_value( 'show-on-post' ) )
|
||||
return false;
|
||||
|
||||
$information = new Types_Information_Controller;
|
||||
$information->prepare();
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This controller extends all post edit pages
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Page_Extension_Edit_Post_Fields {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
if( ! isset( $_GET['group_id'] ) )
|
||||
return;
|
||||
|
||||
$group_id = (int) $_GET['group_id'];
|
||||
|
||||
$post_types = get_post_meta( $group_id, '_wp_types_group_post_types', 'string' );
|
||||
$post_types = explode( ',', $post_types );
|
||||
$post_types = array_values( array_filter( $post_types ) );
|
||||
|
||||
if( count( $post_types ) != 1 || $post_types[0] == 'all' )
|
||||
return;
|
||||
|
||||
Types_Helper_Placeholder::set_post_type( $post_types[0] );
|
||||
Types_Helper_Condition::set_post_type( $post_types[0] );
|
||||
|
||||
$this->prepare();
|
||||
}
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
public function prepare() {
|
||||
// documentation urls
|
||||
Types_Helper_Url::load_documentation_urls();
|
||||
|
||||
// set analytics medium
|
||||
Types_Helper_Url::set_medium( 'field_group_editor' );
|
||||
|
||||
// add informations
|
||||
$this->prepare_informations();
|
||||
|
||||
}
|
||||
|
||||
private function prepare_informations() {
|
||||
$setting = new Types_Setting_Preset_Information_Table();
|
||||
|
||||
if( ! $setting->get_value( 'show-on-field-group' ) )
|
||||
return false;
|
||||
|
||||
$information = new Types_Information_Controller;
|
||||
$information->prepare();
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This controller extends all post edit pages
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Page_Extension_Edit_Post_Type {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
private function __construct() {
|
||||
if( ! isset( $_GET['wpcf-post-type'] ) )
|
||||
return;
|
||||
|
||||
$wpcf_post_type = sanitize_text_field( $_GET['wpcf-post-type'] );
|
||||
|
||||
Types_Helper_Placeholder::set_post_type( $wpcf_post_type );
|
||||
Types_Helper_Condition::set_post_type( $wpcf_post_type );
|
||||
|
||||
$this->prepare();
|
||||
}
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
public function prepare() {
|
||||
// documentation urls
|
||||
Types_Helper_Url::load_documentation_urls();
|
||||
|
||||
// set analytics medium
|
||||
Types_Helper_Url::set_medium( 'cpt_editor' );
|
||||
|
||||
// add informations
|
||||
$this->prepare_informations();
|
||||
|
||||
}
|
||||
|
||||
private function prepare_informations() {
|
||||
$setting = new Types_Setting_Preset_Information_Table();
|
||||
|
||||
if( ! $setting->get_value( 'show-on-post-type' ) )
|
||||
return false;
|
||||
|
||||
$information = new Types_Information_Controller;
|
||||
$information->prepare();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class Types_Page_Extension_Settings
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
class Types_Page_Extension_Settings {
|
||||
|
||||
public function build() {
|
||||
// general tab
|
||||
add_filter( 'toolset_filter_toolset_register_settings_general_section', array( $this, 'general' ), 10, 2 );
|
||||
|
||||
// script
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'on_admin_enqueue_scripts' ) );
|
||||
add_action( 'admin_print_scripts', array( $this, 'print_admin_scripts' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* General Tab
|
||||
*
|
||||
* @param $sections
|
||||
* @param $toolset_options
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function general( $sections, $toolset_options ) {
|
||||
|
||||
$view = new Types_Helper_Twig();
|
||||
|
||||
// Information Table
|
||||
$setting = new Types_Setting_Preset_Information_Table();
|
||||
|
||||
$sections[$setting->get_id()] = array(
|
||||
'slug' => $setting->get_id(),
|
||||
'title' => __( '"Front-end Display" table', 'wpcf' ),
|
||||
'content' => $view->render(
|
||||
'/setting/checkbox.twig',
|
||||
array(
|
||||
'description' => __( 'Show information about Template, Archive, Views and Forms on:', 'wpcf' ),
|
||||
'setting' => $setting,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Scripts
|
||||
*/
|
||||
public function on_admin_enqueue_scripts() {
|
||||
// script
|
||||
wp_enqueue_script(
|
||||
'types-toolset-settings',
|
||||
TYPES_RELPATH . '/public/js/settings.js',
|
||||
array(),
|
||||
TYPES_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public function print_admin_scripts() {
|
||||
echo '<script id="types_model_data" type="text/plain">'.base64_encode( wp_json_encode( $this->build_js_data() ) ).'</script>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build data to be passed to JavaScript.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
private function build_js_data() {
|
||||
|
||||
$types_settings_action = Types_Ajax::get_instance()->get_action_js_name( Types_Ajax::CALLBACK_SETTINGS_ACTION );
|
||||
|
||||
return array(
|
||||
'ajaxInfo' => array(
|
||||
'fieldAction' => array(
|
||||
'name' => $types_settings_action,
|
||||
'nonce' => wp_create_nonce( $types_settings_action )
|
||||
)
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,619 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* "Field Control" page controller.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Page_Field_Control extends Types_Page_Abstract {
|
||||
|
||||
|
||||
/** Name of the URL parameter for the field domain. */
|
||||
const PARAM_DOMAIN = 'domain';
|
||||
|
||||
|
||||
// Screen options...
|
||||
const SCREEN_OPTION_PER_PAGE_NAME = 'types_field_control_fields_per_page';
|
||||
const SCREEN_OPTION_PER_PAGE_DEFAULT_VALUE = 20;
|
||||
|
||||
|
||||
/** @var string Current field domain. Will be populated during self::prepare(). Never access directly. */
|
||||
private $current_domain;
|
||||
|
||||
|
||||
private static $instance;
|
||||
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
private function __construct() { }
|
||||
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
/**
|
||||
* Generate full URL to the Field Control page for given field domain.
|
||||
*
|
||||
* @param string $domain
|
||||
* @return null|string The URL or null if the domain was invalid.
|
||||
* @since 2.0
|
||||
*/
|
||||
public static function get_page_url( $domain ) {
|
||||
|
||||
if( !in_array( $domain, Types_Field_Utils::get_domains() ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return esc_url_raw(
|
||||
add_query_arg(
|
||||
array( 'page' => Types_Admin_Menu::PAGE_NAME_FIELD_CONTROL, 'domain' => $domain ),
|
||||
admin_url( 'admin.php' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* Validate field domain, which must be part of the GET request.
|
||||
*
|
||||
* @throws InvalidArgumentException when the domain is invalid.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function prepare() {
|
||||
|
||||
parent::prepare();
|
||||
|
||||
$current_domain = $this->get_current_domain();
|
||||
|
||||
// Fail on invalid domain.
|
||||
if( null == $current_domain ) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf(
|
||||
__( 'Invalid field domain provided. Expected one of those values: %s', 'wpcf' ),
|
||||
implode( ', ', Types_Field_Utils::get_domains() )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'on_admin_enqueue_scripts' ) );
|
||||
|
||||
add_action( 'current_screen', array( $this, 'prepare_dialogs' ) );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return string
|
||||
*/
|
||||
public function get_title() {
|
||||
|
||||
switch( $this->get_current_domain() ) {
|
||||
case Types_Field_Utils::DOMAIN_POSTS:
|
||||
return __( 'Post Field Control', 'wpcf' );
|
||||
case Types_Field_Utils::DOMAIN_USERS:
|
||||
return __( 'User Field Control', 'wpcf' );
|
||||
case Types_Field_Utils::DOMAIN_TERMS:
|
||||
return __( 'Term Field Control', 'wpcf' );
|
||||
default:
|
||||
// will never happen
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return callable
|
||||
*/
|
||||
public function get_render_callback() {
|
||||
return array( $this, 'render_page' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return string
|
||||
*/
|
||||
public function get_page_name() {
|
||||
return Types_Admin_Menu::PAGE_NAME_FIELD_CONTROL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return string
|
||||
*/
|
||||
public function get_required_capability() {
|
||||
return 'manage_options'; // todo better role/cap handling
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return callable
|
||||
*/
|
||||
public function get_load_callback() {
|
||||
return array( $this, 'add_screen_options' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Current field domain.
|
||||
*
|
||||
* @return string|null
|
||||
* @since 2.0
|
||||
*/
|
||||
private function get_current_domain() {
|
||||
if( null == $this->current_domain ) {
|
||||
$this->current_domain = wpcf_getget( self::PARAM_DOMAIN, null, Types_Field_Utils::get_domains() );
|
||||
}
|
||||
return $this->current_domain;
|
||||
}
|
||||
|
||||
|
||||
public function on_admin_enqueue_scripts() {
|
||||
|
||||
$main_handle = 'types-page-field-control-main';
|
||||
|
||||
// Enqueuing with the wp-admin dependency because we need to override something !important.
|
||||
Types_Asset_Manager::get_instance()->enqueue_styles(
|
||||
array(
|
||||
'wp-admin',
|
||||
'common',
|
||||
'font-awesome',
|
||||
'wpcf-css-embedded',
|
||||
'wp-jquery-ui-dialog'
|
||||
)
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
$main_handle,
|
||||
TYPES_RELPATH . '/public/page/field_control/style.css'
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
$main_handle,
|
||||
TYPES_RELPATH . '/public/page/field_control/main.js',
|
||||
array(
|
||||
'jquery', 'backbone', 'underscore',
|
||||
Types_Asset_Manager::SCRIPT_HEADJS,
|
||||
Types_Asset_Manager::SCRIPT_ADJUST_MENU_LINK,
|
||||
Types_Asset_Manager::SCRIPT_KNOCKOUT,
|
||||
Types_Asset_Manager::SCRIPT_UTILS
|
||||
),
|
||||
TYPES_VERSION
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private $twig = null;
|
||||
|
||||
|
||||
private function get_twig() {
|
||||
if( null == $this->twig ) {
|
||||
$loader = new Twig_Loader_Filesystem();
|
||||
$loader->addPath( TYPES_ABSPATH . '/application/views/page', 'generic_page' );
|
||||
$loader->addPath( TYPES_ABSPATH . '/application/views/page/field_control', 'field_control' );
|
||||
$this->twig = new Twig_Environment( $loader );
|
||||
}
|
||||
return $this->twig;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function render_page() {
|
||||
|
||||
$context = $this->build_page_context();
|
||||
|
||||
echo $this->get_twig()->render( '@field_control/main.twig', $context );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the context for main poge template.
|
||||
*
|
||||
* That includes variables for the template as well as data to be passed to JavaScript.
|
||||
*
|
||||
* @return array Page context. See the main page template for details.
|
||||
* @since 2.0
|
||||
*/
|
||||
private function build_page_context() {
|
||||
|
||||
$context = array(
|
||||
'strings' => $this->build_strings_for_twig(),
|
||||
'js_model_data' => base64_encode( wp_json_encode( $this->build_js_data() ) ),
|
||||
'assets' => array(
|
||||
'loaderOverlay' => Types_Assets::get_instance()->get_image_url( Types_Assets::IMG_AJAX_LOADER_OVERLAY )
|
||||
)
|
||||
);
|
||||
|
||||
return $context;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build data to be passed to JavaScript.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
private function build_js_data() {
|
||||
|
||||
$field_action_name = Types_Ajax::get_instance()->get_action_js_name( Types_Ajax::CALLBACK_FIELD_CONTROL_ACTION );
|
||||
|
||||
return array(
|
||||
'jsIncludePath' => TYPES_RELPATH . '/public/page/field_control',
|
||||
'fieldDefinitions' => $this->build_field_definitions(),
|
||||
'fieldTypeDefinitions' => Types_Field_Type_Definition_Factory::get_instance()->get_field_type_definitions(),
|
||||
'templates' => $this->build_templates(),
|
||||
'strings' => $this->build_strings_for_js(),
|
||||
'ajaxInfo' => array(
|
||||
'fieldAction' => array(
|
||||
'name' => $field_action_name,
|
||||
'nonce' => wp_create_nonce( $field_action_name )
|
||||
)
|
||||
),
|
||||
'currentDomain' => $this->get_current_domain(),
|
||||
'groups' => $this->build_group_data(),
|
||||
'typeConversionMatrix' => Types_Field_Type_Converter::get_instance()->get_conversion_matrix(),
|
||||
'itemsPerPage' => $this->get_items_per_page_setting()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare field definition data, depending on current field domain, for passing to JavaScript.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
private function build_field_definitions() {
|
||||
|
||||
$query_args = array(
|
||||
'filter' => 'all',
|
||||
'orderby' => 'name',
|
||||
'order' => 'asc'
|
||||
);
|
||||
|
||||
$definitions = array();
|
||||
switch( $this->get_current_domain() ) {
|
||||
case Types_Field_Utils::DOMAIN_POSTS:
|
||||
$definitions = WPCF_Field_Definition_Factory_Post::get_instance()->query_definitions( $query_args );
|
||||
break;
|
||||
case Types_Field_Utils::DOMAIN_USERS:
|
||||
$definitions = WPCF_Field_Definition_Factory_User::get_instance()->query_definitions( $query_args );
|
||||
break;
|
||||
case Types_Field_Utils::DOMAIN_TERMS:
|
||||
$definitions = WPCF_Field_Definition_Factory_Term::get_instance()->query_definitions( $query_args );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$definition_data = array();
|
||||
foreach( $definitions as $definition ) {
|
||||
$definition_data[] = $definition->to_json();
|
||||
}
|
||||
|
||||
return $definition_data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build array of templates that will be passed to JavaScript.
|
||||
*
|
||||
* If the template file does not exist or is not readable, it will be silently omitted.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
private function build_templates() {
|
||||
|
||||
$template_sources = array(
|
||||
'messageDefinitionList' => 'field_control/message_definition_list.html',
|
||||
'messageMultiple' => 'field_control/message_multiple.html',
|
||||
);
|
||||
|
||||
$templates = array();
|
||||
foreach( $template_sources as $template_name => $template_relpath ) {
|
||||
|
||||
$template_path = TYPES_ABSPATH . '/application/views/page/' . $template_relpath;
|
||||
|
||||
if( file_exists( $template_path ) ) {
|
||||
$templates[ $template_name ] = file_get_contents( $template_path );
|
||||
}
|
||||
}
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
||||
|
||||
private function build_strings_for_twig() {
|
||||
|
||||
return array(
|
||||
'column' => array(
|
||||
'name' => __( 'Field name', 'wpcf' ),
|
||||
'slug' => __( 'Slug', 'wpcf' ),
|
||||
'metaKey' => __( 'Meta key', 'wpcf' ),
|
||||
'groups' => __( 'Field groups', 'wpcf' ),
|
||||
'type' => __( 'Type' )
|
||||
),
|
||||
'rowAction' => array(
|
||||
'changeAssignment' => __( 'Change assignment', 'wpcf' ),
|
||||
'changeType' => __( 'Change type', 'wpcf' ),
|
||||
'delete' => __( 'Delete', 'wpcf' )
|
||||
),
|
||||
'misc' => array(
|
||||
'noItemsFound' => __( 'No field definitions found.', 'wpcf' ),
|
||||
'applyBulkAction' => __( 'Apply', 'wpcf' ),
|
||||
'searchPlaceholder' => __( 'Search', 'wpcf' ),
|
||||
'pageTitle' => $this->get_title(),
|
||||
'items' => __( 'items', 'wpcf' ),
|
||||
'of' => __( 'of', 'wpcf' ),
|
||||
'thisFieldIsRepeating' => __( 'This is a repeating field.', 'wpcf' )
|
||||
),
|
||||
'bulkAction' => array(
|
||||
'select' => __( 'Bulk action', 'wpcf' ),
|
||||
'delete' => __( 'Delete', 'wpcf' ),
|
||||
'manageWithTypes' => __( 'Manage with Types', 'wpcf' ),
|
||||
'stopManagingWithTypes' => __( 'Stop managing with Types', 'wpcf' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Prepare an array of strings used in JavaScript.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
private function build_strings_for_js() {
|
||||
return array(
|
||||
'misc' => array(
|
||||
'notManagedByTypes' => __( 'Not managed by Types', 'wpcf'),
|
||||
'undefinedAjaxError' => __( 'The action was not successful, an unknown error has happened.', 'wpcf' ),
|
||||
'genericSuccess' => __( 'The action was completed successfully.', 'wpcf' ),
|
||||
'fieldsAlreadyManaged' => __( 'Some of the fields you selected are already managed by Types.', 'wpcf' ),
|
||||
'fieldsAlreadyUnmanaged' => __( 'Some of the fields you selected are already not managed by Types.', 'wpcf' ),
|
||||
'unselectAndRetry' => __( 'Please unselect them and try again.', 'wpcf' ),
|
||||
'changeAssignmentToGroups' => __( 'Change assignment to field groups for the field', 'wpcf' ),
|
||||
'deleteField' => __( 'Delete field', 'wpcf' ),
|
||||
'deleteFields' => __( 'Delete multiple fields', 'wpcf' ),
|
||||
'cannotDeleteUnmanagedFields' => __( 'Some fields cannot be deleted because they are not managed by Types.', 'wpcf' ),
|
||||
'changeFieldType' => __( 'Change field type for the field', 'wpcf' ),
|
||||
'startManagingFieldsWithTypes' => __( 'Start managing fields with Types', 'wpcf' ),
|
||||
'stopManagingFieldsWithTypes' => __( 'Stop managing fields with Types', 'wpcf' )
|
||||
),
|
||||
'rowAction' => array(
|
||||
'manageByTypes' => array(
|
||||
'yes' => __( 'Manage with Types', 'wpcf' ),
|
||||
'no' => __( 'Stop managing with Types', 'wpcf' )
|
||||
),
|
||||
'changeCardinality' => array(
|
||||
'makeRepetitive' => __( 'Turn into repetitive', 'wpcf' ),
|
||||
'makeSingle' => __( 'Turn into single-value', 'wpcf' )
|
||||
)
|
||||
),
|
||||
'bulkAction' => array(
|
||||
'select' => __( 'Bulk action', 'wpcf' ),
|
||||
'delete' => __( 'Delete', 'wpcf' ),
|
||||
'manageWithTypes' => __( 'Manage with Types', 'wpcf' ),
|
||||
'stopManagingWithTypes' => __( 'Stop managing with Types', 'wpcf' )
|
||||
),
|
||||
'button' => array(
|
||||
'apply' => __( 'Apply', 'wpcf' ),
|
||||
'cancel' => __( 'Cancel', 'wpcf' ),
|
||||
'delete' => __( 'Delete', 'wpcf' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build an array describing existing field groups within the domain.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
private function build_group_data() {
|
||||
$factory = Types_Field_Utils::get_group_factory_by_domain( $this->get_current_domain() );
|
||||
$groups = $factory->query_groups();
|
||||
|
||||
$group_data = array();
|
||||
foreach( $groups as $group ) {
|
||||
$group_data[ $group->get_slug() ] = array(
|
||||
'slug' => $group->get_slug(),
|
||||
'displayName' => stripslashes( $group->get_display_name() )
|
||||
);
|
||||
}
|
||||
|
||||
return $group_data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display screen options on the page.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function add_screen_options() {
|
||||
|
||||
$args = array(
|
||||
'label' => __( 'Number of displayed fields', 'wpcf' ),
|
||||
'default' => self::SCREEN_OPTION_PER_PAGE_DEFAULT_VALUE,
|
||||
'option' => self::SCREEN_OPTION_PER_PAGE_NAME,
|
||||
);
|
||||
add_screen_option( 'per_page', $args );
|
||||
|
||||
add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the "per page" screen option.
|
||||
*
|
||||
* @param $status
|
||||
* @param string $option
|
||||
* @param $value
|
||||
* @return mixed
|
||||
* @since 2.0
|
||||
*/
|
||||
public function set_screen_option( $status, $option, $value ) {
|
||||
|
||||
if ( self::SCREEN_OPTION_PER_PAGE_NAME == $option ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $status;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Value of the "items per page" setting for current page and current user.
|
||||
*
|
||||
* @return int
|
||||
* @since 2.0
|
||||
*/
|
||||
private function get_items_per_page_setting() {
|
||||
$user = get_current_user_id();
|
||||
$screen = get_current_screen();
|
||||
$option = $screen->get_option( 'per_page', 'option' );
|
||||
$per_page = get_user_meta( $user, $option, true );
|
||||
if ( empty ( $per_page ) || $per_page < 1 ) {
|
||||
$per_page = $screen->get_option( 'per_page', 'default' );
|
||||
}
|
||||
|
||||
return (int) $per_page;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Prepare assets for all dialogs that are going to be used on the page.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function prepare_dialogs() {
|
||||
|
||||
new Types_Dialog_Box(
|
||||
'types-change-assignment-dialog',
|
||||
$this->get_twig(),
|
||||
array(
|
||||
'groups' => $this->build_group_data(),
|
||||
'strings' => array(
|
||||
'noFieldGroups' => __( 'No field groups exist yet. You have to create one first.', 'wpcf' )
|
||||
)
|
||||
),
|
||||
'@field_control/change_assignment_dialog.twig'
|
||||
);
|
||||
|
||||
new Types_Dialog_Box(
|
||||
'types-delete-field-dialog',
|
||||
$this->get_twig(),
|
||||
array(
|
||||
'strings' => array(
|
||||
'deletingWillRemoveDefinitionAndData' => __( 'Deleting fields will remove them from all groups and delete the field data from the database as well.', 'wpcf' ),
|
||||
'cannotBeUndone' => __( 'This cannot be undone!', 'wpcf' ),
|
||||
'doYouReallyWantDelete' => __( 'Do you really want to delete?', 'wpcf' )
|
||||
)
|
||||
),
|
||||
'@field_control/delete_dialog.twig'
|
||||
);
|
||||
|
||||
new Types_Dialog_Box(
|
||||
'types-change-field-type-dialog',
|
||||
$this->get_twig(),
|
||||
array(
|
||||
'fieldTypeDefinitions' => Types_Field_Type_Definition_Factory::get_instance()->get_field_type_definitions(),
|
||||
'strings' => array(
|
||||
'aboutFieldTypeChanging' => __( 'Select a new type for this field.', 'wpcf' ),
|
||||
'someTypesAreDisabled' => __( 'Note: Some of the field types are disabled for conversion because they\'re using a significantly different data format, which is not compatible with the current field type.', 'wpcf' ),
|
||||
'potentiallyRiskyOperation' => __( 'Changing field type is a potentially risky operation. Make sure you know what you are doing.', 'wpcf' ),
|
||||
'singleOrRepeatingField' => __( 'Single or repeating field', 'wpcf' ),
|
||||
'repetitiveField' => __( 'Allow multiple instances of this field', 'wpcf' ),
|
||||
'singleField' => __( 'This field can have only one value', 'wpcf' ),
|
||||
'targetSupportsSingleOnly' => __( 'Selected field type supports only single fields.', 'wpcf' ),
|
||||
'repetitiveToSingleWarning' => __( 'Changing from repeating to single field <strong>will cause partial data loss</strong> if there already are fields with multiple values stored in the database. In such case, only one of those value will be saved on update and some inconsistencies appear when displaying values of this field.', 'wpcf' )
|
||||
)
|
||||
),
|
||||
'@field_control/change_type_dialog.twig'
|
||||
);
|
||||
|
||||
|
||||
new Types_Dialog_Box(
|
||||
'types-bulk-change-management-status-dialog',
|
||||
$this->get_twig(),
|
||||
array(
|
||||
'strings' => array(
|
||||
'youAreAboutToManageFields' => __( 'You are about to start managing these fields with Types:', 'wpcf' ),
|
||||
'youAreAboutToStopManagingFields' => __( 'You are about to stop managing these fields with Types:', 'wpcf' ),
|
||||
'confirmContinue' => __( 'Do you want to continue?', 'wpcf' )
|
||||
)
|
||||
),
|
||||
'@field_control/bulk_change_management_status_dialog.twig'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get help configuration for Types_Asset_Help_Tab_Loader.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_help_config() {
|
||||
return array(
|
||||
'title' => $this->get_title(),
|
||||
'template' => '@help/basic.twig',
|
||||
'context' => array(
|
||||
'introductory_paragraphs' => array(
|
||||
__( 'Types plugin provides you with a powerful way to control the Post/User/Term fields.', 'wpcf' ),
|
||||
__( 'On this page you can see the list of all the custom fields present in your site. Some of them were created by Types and some were not.', 'wpcf' ),
|
||||
__( 'When changing changing properties of existing fields, caution is strongly advised because wrong usage can cause issues with themes, plugins and functionality connected to the applied changes.', 'wpcf' )
|
||||
),
|
||||
'your_options' => __( 'You have the following options:', 'wpcf' ),
|
||||
'options' => array(
|
||||
array(
|
||||
'name' => __( 'Change assignment', 'wpcf' ),
|
||||
'explanation' => __( 'Change a group that the field belongs to.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Change type', 'wpcf' ),
|
||||
'explanation' => __( 'Change the type of the field and change whether field can have a single value or multiple values (repetitive field).', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Manage with Types', 'wpcf' ),
|
||||
'explanation' => __( 'Select whether the field is under the control of Types plugin.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'name' => __( 'Delete', 'wpcf' ),
|
||||
'explanation' =>
|
||||
__( 'Click to delete a field and all of its values from the database.', 'wpcf' )
|
||||
. ' <strong>' . __( 'Warning: This cannot be undone.', 'wpcf' ) . '</strong>'
|
||||
)
|
||||
),
|
||||
'ending_paragraphs' => array(
|
||||
__( 'Note: An asterisk (*) beside a field type marks a repeating field.', 'wpcf' )
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Page_Hidden_Helper
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Page_Hidden_Helper extends Types_Page_Abstract {
|
||||
|
||||
private static $instance;
|
||||
|
||||
private $redirect_url = false;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
self::$instance->add_sneaky_hidden_helper();
|
||||
}
|
||||
}
|
||||
|
||||
public function add_sneaky_hidden_helper() {
|
||||
add_submenu_page(
|
||||
'options.php', // hidden
|
||||
$this->get_title(),
|
||||
$this->get_title(),
|
||||
$this->get_required_capability(),
|
||||
$this->get_page_name(),
|
||||
array( $this, $this->get_load_callback() )
|
||||
);
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return 'Loading...';
|
||||
}
|
||||
|
||||
public function get_render_callback() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get_load_callback() {
|
||||
return 'route';
|
||||
}
|
||||
|
||||
public function get_page_name() {
|
||||
return Types_Admin_Menu::PAGE_NAME_HELPER;
|
||||
}
|
||||
|
||||
public function get_required_capability() {
|
||||
return 'manage_options';
|
||||
}
|
||||
|
||||
public function route() {
|
||||
|
||||
$this->redirect_url = false;
|
||||
|
||||
if( isset( $_GET['action'] ) && isset( $_GET['type'] ) ) {
|
||||
|
||||
$action = sanitize_text_field( $_GET['action'] );
|
||||
$type = sanitize_text_field( $_GET['type'] );
|
||||
|
||||
switch( $action ) {
|
||||
case 'new-form':
|
||||
$this->redirect_url = $this->new_form_action( $type );
|
||||
break;
|
||||
case 'new-view':
|
||||
$this->redirect_url = $this->new_view_action( $type );
|
||||
break;
|
||||
case 'new-layout-template':
|
||||
$this->redirect_url = $this->new_layout_template_action( $type );
|
||||
break;
|
||||
case 'new-content-template':
|
||||
$this->redirect_url = $this->new_content_template_action( $type );
|
||||
break;
|
||||
case 'new-wordpress-archive':
|
||||
$this->redirect_url = $this->new_wordpress_archive_action( $type );
|
||||
break;
|
||||
case 'new-post-field-group':
|
||||
$this->redirect_url = $this->new_post_field_group_action( $type );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->redirect_url = $this->add_params_to_url( $this->redirect_url );
|
||||
$this->redirect();
|
||||
}
|
||||
|
||||
private function new_form_action( $type ) {
|
||||
$new_form = new Types_Helper_Create_Form();
|
||||
|
||||
if( $id = $new_form->for_post( $type ) ) {
|
||||
return get_edit_post_link( $id, 'Please WordPress, be so nice and do not encode &.' );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function new_view_action( $type ) {
|
||||
$new_view = new Types_Helper_Create_View();
|
||||
|
||||
if( $id = $new_view->for_post( $type ) ) {
|
||||
return admin_url() . 'admin.php?page=views-editor&view_id='.$id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function new_layout_template_action( $type ) {
|
||||
$new_layout = new Types_Helper_Create_Layout();
|
||||
|
||||
if( $id = $new_layout->for_post( $type ) ) {
|
||||
return admin_url() . 'admin.php?page=dd_layouts_edit&action=edit&layout_id='.$id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function new_content_template_action( $type ) {
|
||||
$new_layout = new Types_Helper_Create_Content_Template();
|
||||
|
||||
if( $id = $new_layout->for_post( $type ) ) {
|
||||
return admin_url() . 'admin.php?page=ct-editor&ct_id='.$id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function new_wordpress_archive_action( $type ) {
|
||||
$new_wordpress_archive = new Types_Helper_Create_Wordpress_Archive();
|
||||
|
||||
if( $id = $new_wordpress_archive->for_post( $type ) ) {
|
||||
return admin_url() . 'admin.php?page=view-archives-editor&view_id='.$id;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function new_post_field_group_action( $type ) {
|
||||
|
||||
$type_object = get_post_type_object( $type );
|
||||
$title = sprintf( __( 'Field Group for %s', 'wpcf' ), $type_object->labels->name );
|
||||
$name = sanitize_title( $title );
|
||||
|
||||
$new_post_field_group = Types_Field_Group_Post_Factory::get_instance()->create( $name, $title, 'publish' );
|
||||
|
||||
if( ! $new_post_field_group )
|
||||
return false;
|
||||
|
||||
$new_post_field_group->assign_post_type( $type );
|
||||
|
||||
$url = isset( $_GET['ref'] )
|
||||
? 'admin.php?page=wpcf-edit&group_id='.$new_post_field_group->get_id().'&ref='.sanitize_text_field( $_GET['ref'] )
|
||||
: 'admin.php?page=wpcf-edit&group_id='.$new_post_field_group->get_id();
|
||||
|
||||
return admin_url( $url );
|
||||
}
|
||||
|
||||
private function add_params_to_url( $url ) {
|
||||
// forward parameter toolset_help_video
|
||||
if( isset( $_GET['toolset_help_video'] ) )
|
||||
$url = add_query_arg( 'toolset_help_video', sanitize_text_field( $_GET['toolset_help_video'] ), $url );
|
||||
|
||||
// forward parameter ref
|
||||
if( isset( $_GET['ref'] ) )
|
||||
$url = add_query_arg( 'ref', sanitize_text_field( $_GET['ref'] ), $url );
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* hidden page, but only when redirect after doing what we have to do
|
||||
*/
|
||||
private function redirect() {
|
||||
// shouldn't happen but if we have no redirect_url here: goto admin main page.
|
||||
if( ! $this->redirect_url )
|
||||
$this->redirect_url = admin_url();
|
||||
|
||||
die( '<script type="text/javascript">'.'window.location = "' . $this->redirect_url . '";'.'</script>' );
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Twig.
|
||||
*
|
||||
* (c) 2009 Fabien Potencier
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Autoloads Twig classes.
|
||||
*
|
||||
* This is a modified version of Twig_Autoloader that survives without producing a fatal error even if someone else
|
||||
* includes Twig_Autoloader recklessly, without checking if !class_exists(). When the register() method is being
|
||||
* called, it checks all registered autoloaders. If the native Twig_Autoloader is already there, this class resigns
|
||||
* and doesn't complete it's own registration.
|
||||
*
|
||||
* This will, however, work only if it happens late enough. In Types we assume that it is ok to do this during 'init'.
|
||||
* The one known issue is with older WPML versions that register Twig right when the plugin is loaded.
|
||||
*
|
||||
* Note: Twig_Autoloader is marked as deprecated, however we can't easily use the proposed composer autoloader, since
|
||||
* that breaks the PHP 5.2 compatibility.
|
||||
*
|
||||
* The original author of this class:
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Twig_Autoloader
|
||||
{
|
||||
|
||||
/**
|
||||
* Registers Types_Twig_Autoloader as an SPL autoloader if Twig_Autoloader isn't already registered.
|
||||
*
|
||||
* @param bool $prepend Whether to prepend the autoloader or not.
|
||||
*/
|
||||
public static function register($prepend = false)
|
||||
{
|
||||
$autoloaders = spl_autoload_functions();
|
||||
foreach( $autoloaders as $autoloader ) {
|
||||
|
||||
// Resign if we detect Twig_Autoloader
|
||||
if( is_array( $autoloader )
|
||||
&& 2 == count( $autoloader )
|
||||
&& is_string( $autoloader[0] )
|
||||
&& 'Twig_Autoloader' == $autoloader[0]
|
||||
&& is_string( $autoloader[1] )
|
||||
&& 'autoload' == $autoloader[1]
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID < 50300) {
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'));
|
||||
} else {
|
||||
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles autoloading of classes.
|
||||
*
|
||||
* @param string $class A class name.
|
||||
*/
|
||||
public static function autoload($class)
|
||||
{
|
||||
if (0 !== strpos($class, 'Twig')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Modified path to Twig in Types.
|
||||
$file = TYPES_ABSPATH . '/vendor/twig/twig/lib/' . str_replace( array( '_', "\0" ), array( '/', '' ), $class .'.php' );
|
||||
|
||||
if( is_file( $file ) ) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,279 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Plugin upgrade controller.
|
||||
*
|
||||
* Compares current plugin version with a version number stored in the database, and performs upgrade routines if
|
||||
* necessary.
|
||||
*
|
||||
* Note: Filters to add upgrade routines are not provided on purpose, so all routines need to be defined here.
|
||||
*
|
||||
* It works with version numbers, which are easier to compare and manipulate with. See convert_version_string_to_number()
|
||||
* for details.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
class Types_Upgrade {
|
||||
|
||||
private static $instance;
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
private function __construct() { }
|
||||
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
public static function initialize() {
|
||||
$instance = self::get_instance();
|
||||
$instance->check_upgrade();
|
||||
}
|
||||
|
||||
|
||||
// Legacy option names used to store version string.
|
||||
const TYPES_DATABASE_VERSION_OPTION_LEGACY1 = 'WPCF_VERSION';
|
||||
const TYPES_DATABASE_VERSION_OPTION_LEGACY2 = 'wpcf-version';
|
||||
|
||||
/** Name of the option used to store version number. */
|
||||
const TYPES_DATABASE_VERSION_OPTION = 'types_database_version';
|
||||
|
||||
|
||||
/**
|
||||
* Check if an upgrade is needed, and if yes, perform it.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public function check_upgrade() {
|
||||
|
||||
if( $this->is_upgrade_needed() ) {
|
||||
$this->do_upgrade();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if an upgrade is needed.
|
||||
*
|
||||
* @return bool
|
||||
* @since 2.1
|
||||
*/
|
||||
private function is_upgrade_needed() {
|
||||
return ( $this->get_database_version() < $this->get_plugin_version() );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get current plugin version number.
|
||||
*
|
||||
* @return int
|
||||
* @since 2.1
|
||||
*/
|
||||
private function get_plugin_version() {
|
||||
return $this->convert_version_string_to_number( TYPES_VERSION );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get number of the version stored in the database.
|
||||
*
|
||||
* @return int
|
||||
* @since 2.1
|
||||
*/
|
||||
private function get_database_version() {
|
||||
$version = (int) get_option( self::TYPES_DATABASE_VERSION_OPTION, 0 );
|
||||
|
||||
if( 0 === $version ) {
|
||||
$version = get_option( self::TYPES_DATABASE_VERSION_OPTION_LEGACY1, 0 );
|
||||
|
||||
if( 0 === $version ) {
|
||||
$version = get_option( self::TYPES_DATABASE_VERSION_OPTION_LEGACY2, 0 );
|
||||
}
|
||||
|
||||
$version = $this->convert_version_string_to_number( $version );
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Transform a version string to a version number.
|
||||
*
|
||||
* The version string looks like this: "major.minor[.maintenance[.revision]]". We expect that all parts have
|
||||
* two digits at most.
|
||||
*
|
||||
* Conversion to version number is done like this:
|
||||
* $ver_num = MAJOR * 1000000
|
||||
* + MINOR * 10000
|
||||
* + MAINTENANCE * 100
|
||||
* + REVISION * 1
|
||||
*
|
||||
* That means, for example "1.8.11.12" will be equal to:
|
||||
* 1000000
|
||||
* + 80000
|
||||
* + 1100
|
||||
* + 12
|
||||
* ---------
|
||||
* = 1081112
|
||||
*
|
||||
* @param string $version_string
|
||||
* @return int
|
||||
* @since 2.1
|
||||
*/
|
||||
private function convert_version_string_to_number( $version_string ) {
|
||||
|
||||
if( 0 === $version_string ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$version_parts = explode( '.', $version_string );
|
||||
$multipliers = array( 1000000, 10000, 100, 1 );
|
||||
|
||||
$version_part_count = count( $version_parts );
|
||||
$version = 0;
|
||||
for( $i = 0; $i < $version_part_count; ++$i ) {
|
||||
$version_part = (int) $version_parts[ $i ];
|
||||
$multiplier = $multipliers[ $i ];
|
||||
|
||||
$version += $version_part * $multiplier;
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the version number stored in the database.
|
||||
*
|
||||
* @param int $version_number
|
||||
* @since 2.1
|
||||
*/
|
||||
private function update_database_version( $version_number ) {
|
||||
if( is_numeric( $version_number ) ) {
|
||||
update_option( self::TYPES_DATABASE_VERSION_OPTION, (int) $version_number );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an array of upgrade routines.
|
||||
*
|
||||
* Each routine is defined as an associative array with two elements:
|
||||
* - 'version': int, which specifies the *target* version after the upgrade
|
||||
* - 'callback': callable
|
||||
*
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
private function get_upgrade_routines() {
|
||||
|
||||
$upgrade_routines = array(
|
||||
array(
|
||||
'version' => 2010000,
|
||||
'callback' => array( $this, 'upgrade_db_to_2010000' )
|
||||
),
|
||||
array(
|
||||
'version' => 2021600,
|
||||
'callback' => array( $this, 'upgrade_db_to_2021600' )
|
||||
)
|
||||
);
|
||||
|
||||
return $upgrade_routines;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform the upgrade by calling the appropriate upgrade routines and updating the version number in the database.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
private function do_upgrade() {
|
||||
|
||||
$from_version = $this->get_database_version();
|
||||
$upgrade_routines = $this->get_upgrade_routines();
|
||||
$target_version = $this->get_plugin_version();
|
||||
|
||||
// Sort upgrade routines by their version.
|
||||
$routines_by_version = array();
|
||||
foreach( $upgrade_routines as $key => $row ) {
|
||||
$routines_by_version[ $key ] = $row['version'];
|
||||
}
|
||||
array_multisort( $routines_by_version, SORT_DESC, $upgrade_routines );
|
||||
|
||||
// Run all the routines necessary
|
||||
foreach( $upgrade_routines as $routine ) {
|
||||
$upgrade_version = (int) wpcf_getarr( $routine, 'version' );
|
||||
|
||||
if( $from_version < $upgrade_version && $upgrade_version <= $target_version ) {
|
||||
$callback = wpcf_getarr( $routine, 'callback' );
|
||||
if( is_callable( $callback ) ) {
|
||||
call_user_func( $callback );
|
||||
}
|
||||
$this->update_database_version( $upgrade_version );
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, update to current plugin version even if there are no other routines to run, so that
|
||||
// this method is not called every time by check_upgrade().
|
||||
$this->update_database_version( $target_version );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upgrade database to 2010000 (Types 2.1)
|
||||
*
|
||||
* Batch fix types-768 for all non-superadmin users.
|
||||
*/
|
||||
function upgrade_db_to_2010000() {
|
||||
|
||||
$roles_manager = WPCF_Roles::getInstance();
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// Will find users without the administrator roles but with one of the Types management roles.
|
||||
// A sign of the types-768 bug.
|
||||
$user_query = new WP_User_Query(
|
||||
array(
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => $wpdb->prefix . 'capabilities',
|
||||
'value' => '"administrator"',
|
||||
'compare' => 'NOT LIKE',
|
||||
),
|
||||
array(
|
||||
'key' => $wpdb->prefix . 'capabilities',
|
||||
'value' => '"wpcf_custom_post_type_view"',
|
||||
'compare' => 'LIKE',
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$users = $user_query->get_results();
|
||||
|
||||
foreach( $users as $user ) {
|
||||
$roles_manager->clean_the_mess_in_nonadmin_user_caps( $user );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade database to 2021600 (Types 2.2.16)
|
||||
*
|
||||
* Fix types-1142 for non admins with an 'admin' username.
|
||||
*/
|
||||
function upgrade_db_to_2021600() {
|
||||
|
||||
$roles_manager = WPCF_Roles::getInstance();
|
||||
$roles_manager->clean_the_mess_in_nonadmin_user_caps( 'admin' );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Provides a safer access to the option with post type values.
|
||||
*
|
||||
* If the option value is a standard serialized array, the performance is negligible. However, if the option is
|
||||
* malformed by some sort of search-replace in string values (stored string length doesn't match the actual one),
|
||||
* it will try to salvage the situation without the user even noticing.
|
||||
*
|
||||
* It specifically fixes on focusing a bug caused by WordPress 4.8.3 where in a certain situation the post type labels,
|
||||
* which contain the %s placeholder, are damaged by replacing the '%' character by another placeholder (see
|
||||
* https://make.wordpress.org/core/2017/10/31/changed-behaviour-of-esc_sql-in-wordpress-4-8-3/ for details).
|
||||
*
|
||||
* If the option needs to be fixed, we will further try to detect these placeholders in post type labels
|
||||
* and replace them with '%s'. It is very unlikely that someone would save a value like '{18184a8b66ef}s' inside
|
||||
* the label AND that the option becomes malformed at the same time, so we take the risk and replace it with '%s'.
|
||||
*
|
||||
* In order to be able to do this, we need to access the wp_options table directly, because get_option() calls
|
||||
* unserialize() before a filter we could reasonably hook into, and at that point we already get just a 'false' value.
|
||||
*
|
||||
* As a consequence, all occurences of "get_option( WPCF_OPTION_NAME_CUSTOM_TYPES, array() )" must be replaced
|
||||
* by a call to Types_Utils_Post_Type_Option::get_post_types().
|
||||
*
|
||||
* The solution is inspired by https://github.com/Blogestudio/Fix-Serialization/blob/master/fix-serialization.php
|
||||
*
|
||||
* IMPORTANT: Beware that this class is being manually loaded even before Toolset Common in some cases. Do not move it
|
||||
* without considering that and do not use anything fancy like toolset_ensarr() here.
|
||||
*
|
||||
* @since 2.2.18
|
||||
*/
|
||||
class Types_Utils_Post_Type_Option {
|
||||
|
||||
|
||||
/**
|
||||
* Get the post types option.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_post_types() {
|
||||
$post_types = get_option( WPCF_OPTION_NAME_CUSTOM_TYPES, array() );
|
||||
|
||||
if ( ! is_array( $post_types ) ) {
|
||||
$raw_value = $this->get_raw_option();
|
||||
if ( is_string( $raw_value ) && ! empty( $raw_value ) ) {
|
||||
// Now we know that something went seriously wrong AND we probably have post types to save.
|
||||
$post_types = $this->try_fix_serialized_array( $raw_value );
|
||||
$post_types = maybe_unserialize( $post_types );
|
||||
$post_types = $this->try_fix_post_type_labels( $post_types );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! is_array( $post_types ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return $post_types;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the raw WPCF_OPTION_NAME_CUSTOM_TYPES option from the database.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
private function get_raw_option() {
|
||||
global $wpdb;
|
||||
|
||||
$option_value = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT option_value FROM {$wpdb->options} WHERE option_name = %s",
|
||||
WPCF_OPTION_NAME_CUSTOM_TYPES
|
||||
)
|
||||
);
|
||||
|
||||
return $option_value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Restore a broken serialized array by fixing string lengths.
|
||||
*
|
||||
* @param $broken_serialized_array
|
||||
* @return string
|
||||
*/
|
||||
private function try_fix_serialized_array( $broken_serialized_array ) {
|
||||
$output = preg_replace_callback(
|
||||
'!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!',
|
||||
array( $this, 'preg_replace_callback' ),
|
||||
$broken_serialized_array
|
||||
);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fix a string length for a single occurence.
|
||||
*
|
||||
* @param array $matches
|
||||
* @return string
|
||||
*/
|
||||
private function preg_replace_callback( $matches ) {
|
||||
if ( count( $matches ) < 4 ) {
|
||||
// empty string
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
$stored_string = $matches[3];
|
||||
$string_mysql_unescaped = $this->unescape_mysql( $stored_string );
|
||||
$string_length = strlen( $string_mysql_unescaped );
|
||||
$string_without_quotes = $this->unescape_quotes( $stored_string );
|
||||
|
||||
$replacement = 's:' . $string_length . ':"' . $string_without_quotes . '";';
|
||||
|
||||
return $replacement;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the post types option
|
||||
* @param $post_types
|
||||
*/
|
||||
public function update_post_types( $post_types ) {
|
||||
update_option( WPCF_OPTION_NAME_CUSTOM_TYPES, $post_types, true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unescape to avoid dump-text issues.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
private function unescape_mysql( $value ) {
|
||||
return str_replace(
|
||||
array( "\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"' ),
|
||||
array( "\\", "\0", "\n", "\r", "\x1a", "'", '"' ),
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fix strange behaviour if you have escaped quotes in your replacement
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function unescape_quotes( $value ) {
|
||||
return str_replace( '\"', '"', $value );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $post_types
|
||||
* @return array
|
||||
*/
|
||||
private function try_fix_post_type_labels( $post_types ) {
|
||||
foreach ( $post_types as $key => $post_type ) {
|
||||
if ( ! array_key_exists( 'labels', $post_type ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $post_type['labels'] as $label_name => $label_value ) {
|
||||
$fixed_label = preg_replace( '/\{[a-f0-9]{8,}\}s/', '%s', $label_value );
|
||||
$post_types[ $key ]['labels'][ $label_name ] = $fixed_label;
|
||||
}
|
||||
}
|
||||
|
||||
return $post_types;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,369 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/* Post Type with has_archive = false */
|
||||
'no-archive-support' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Archive_No_Support'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The archive is disabled for this post type.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'To enable, go to <a href="%POST-TYPE-EDIT-HAS-ARCHIVE%">Options</a> and mark "has_archive".', 'wpcf' )
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, integrated, Archive missing */
|
||||
'layouts-integrated-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Compatible',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no layout for the %POST-LABEL-PLURAL% archive.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, Archive */
|
||||
'layouts-archive' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Archive_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'link',
|
||||
'label' => '%POST-LAYOUT-ARCHIVE%',
|
||||
'target' => '%POST-EDIT-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, archive */
|
||||
'views-archive' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Archive_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'link',
|
||||
'label' => '%POST-VIEWS-ARCHIVE%',
|
||||
'target' => '%POST-EDIT-VIEWS-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* For posts and pages we always show template file if it exists */
|
||||
'archive-exists-for-posts-pages' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Type_Post_Or_Page',
|
||||
'Types_Helper_Condition_Archive_Exists',
|
||||
'Types_Helper_Condition_Archive_Has_Fields'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( '%POST-ARCHIVE-FILE%', 'wpcf' )
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, has template with missing fields. */
|
||||
'layouts-archive-fields-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing',
|
||||
'Types_Helper_Condition_Archive_No_Fields'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The %POST-LABEL-PLURAL% archive of your theme %POST-ARCHIVE-FILE% is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, single.php exists, but layouts missing */
|
||||
'layouts-php-archive-exists-layouts-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing',
|
||||
'Types_Helper_Condition_Archive_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( '%POST-ARCHIVE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, Archive missing */
|
||||
'layouts-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no layout for the %POST-LABEL-PLURAL% archive.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Archive missing */
|
||||
'archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Archive_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme is missing the standard WordPress archive for %POST-LABEL-PLURAL%.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'resolve-no-archive',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Toolset plugins let you design archive pages without writing PHP. Your archives will include all
|
||||
the fields that you need and your design.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn about creating archives with Toolset', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'creating-archives-with-toolset', 'popup' ),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Archive without Fields */
|
||||
'archive-fields-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Archive_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The %POST-LABEL-PLURAL% archive of your theme is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Resolve', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'resolve-no-custom-fields',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Toolset plugins let you design archives with custom fields, without writing PHP.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn about creating archives with Toolset', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'creating-archives-with-toolset', 'popup' ),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Archive Fields */
|
||||
'archive-fields' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Archive_Has_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( '%POST-ARCHIVE-FILE%', 'wpcf' )
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, has template with missing fields. */
|
||||
'views-archive-fields-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Archive_Missing',
|
||||
'Types_Helper_Condition_Archive_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The %POST-LABEL-PLURAL% archive of your theme %POST-ARCHIVE-FILE% is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button js-toolset-dashboard-create-archive',
|
||||
'target' => '%POST-CREATE-VIEWS-ARCHIVE%',
|
||||
'post_type' => '%POST-CREATE-VIEWS-ARCHIVE-TYPE%',
|
||||
'redirect_url' => '%POST-CREATE-VIEWS-ARCHIVE-REDIRECT-URL%',
|
||||
'forwhomtitle' => '%POST-CREATE-VIEWS-ARCHIVE-FOR-WHOM-TITLE%',
|
||||
'forwhomloop' => '%POST-CREATE-VIEWS-ARCHIVE-FOR-WHOM-LOOP%',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, archive.php exists, but views missing */
|
||||
'views-php-archive-exists-views-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Archive_Missing',
|
||||
'Types_Helper_Condition_Archive_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( '%POST-ARCHIVE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button js-toolset-dashboard-create-archive',
|
||||
'target' => '%POST-CREATE-VIEWS-ARCHIVE%',
|
||||
'post_type' => '%POST-CREATE-VIEWS-ARCHIVE-TYPE%',
|
||||
'redirect_url' => '%POST-CREATE-VIEWS-ARCHIVE-REDIRECT-URL%',
|
||||
'forwhomtitle' => '%POST-CREATE-VIEWS-ARCHIVE-FOR-WHOM-TITLE%',
|
||||
'forwhomloop' => '%POST-CREATE-VIEWS-ARCHIVE-FOR-WHOM-LOOP%',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
/* Views, template missing */
|
||||
'views-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Archive_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no WordPress Archive for %POST-LABEL-PLURAL%.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button js-toolset-dashboard-create-archive',
|
||||
'target' => '%POST-CREATE-VIEWS-ARCHIVE%',
|
||||
'post_type' => '%POST-CREATE-VIEWS-ARCHIVE-TYPE%',
|
||||
'redirect_url' => '%POST-CREATE-VIEWS-ARCHIVE-REDIRECT-URL%',
|
||||
'forwhomtitle' => '%POST-CREATE-VIEWS-ARCHIVE-FOR-WHOM-TITLE%',
|
||||
'forwhomloop' => '%POST-CREATE-VIEWS-ARCHIVE-FOR-WHOM-LOOP%',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
);
|
||||
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/* CRED missing */
|
||||
'cred-missing' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Cred_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create Form', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'create-form',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'To create a form for front-end content submission and editing, you need to have CRED plugin installed.
|
||||
CRED is part of the complete Toolset package for adding and displaying custom content.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn how CRED forms work', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'how-cred-work', 'popup' )
|
||||
),
|
||||
/*
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Free Toolset Trial', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'free-trial', 'popup' )
|
||||
),
|
||||
*/
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* CRED, forms missing */
|
||||
'cred-forms-missing' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Cred_Forms_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-FORM%',
|
||||
'label' => __( 'Create form', 'wpcf' )
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
/* CRED, forms */
|
||||
'cred-forms' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Cred_Active',
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Cred_Forms_Exist'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => '%POST-FORMS-LIST%',
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-FORM%',
|
||||
'label' => __( 'Create form', 'wpcf' )
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
/* CRED & Layouts, forms missing */
|
||||
'cred-layouts-forms-missing' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Cred_Forms_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __(
|
||||
'You can create forms for front-end submission and editing of %POST-LABEL-PLURAL%.', 'wpcf'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'target' => Types_Helper_Url::get_url( 'adding-forms-to-layouts', 'table' ),
|
||||
'label' => __( 'Learn how', 'wpcf' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
/* CRED & Layouts, forms exists */
|
||||
'cred-layouts-forms' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Cred_Forms_Exist'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => '%POST-FORMS-LIST%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'target' => Types_Helper_Url::get_url( 'adding-forms-to-layouts', 'table' ),
|
||||
'label' => __( 'How to add forms to layouts', 'wpcf' )
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
@@ -1,129 +0,0 @@
|
||||
<?php
|
||||
$question_marks = array(
|
||||
|
||||
'type' => array(
|
||||
'id' => 'type',
|
||||
'title' => __( 'Post Type', 'wpcf' ),
|
||||
),
|
||||
|
||||
'fields' => array(
|
||||
'id' => 'fields',
|
||||
'title' => __( 'Fields', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'A list of all Post Fields and their attachment to the Post Types.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-fields', 'tooltip' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
'taxonomies' => array(
|
||||
'id' => 'taxonomies',
|
||||
'title' => __( 'Taxonomies', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'A list of all Taxonomies and their attachment to the Post Types.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-taxonomies', 'tooltip' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'template' => array(
|
||||
'id' => 'template',
|
||||
'title' => __( 'Template', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'A template displays single-item pages with your design and fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-template', 'tooltip' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
'archive' => array(
|
||||
'id' => 'archive',
|
||||
'title' => __( 'Archive', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'An archive is the standard list that WordPress produces for content.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-archive', 'tooltip' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
'views' => array(
|
||||
'id' => 'views',
|
||||
'title' => __( 'Views', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Views are custom lists of content, which you can display anywhere in the site.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-views', 'tooltip' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
'forms' => array(
|
||||
'id' => 'forms',
|
||||
'title' => __( 'Forms', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Forms allow to create and edit content from the site’s front-end.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-forms', 'tooltip' )
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Visual Composer
|
||||
if( defined( 'WPB_VC_VERSION' ) ) {
|
||||
$question_marks['template']['description'][1]['label'] = __( 'Creating templates with Visual Composer', 'wpcf' );
|
||||
}
|
||||
// Beaver Builder
|
||||
else if( class_exists( 'FLBuilderLoader' ) ) {
|
||||
$question_marks['template']['description'][1]['label'] = __( 'Creating templates with Beaver Builder', 'wpcf' );
|
||||
}
|
||||
// Layouts
|
||||
else if( defined( 'WPDDL_DEVELOPMENT' ) || defined( 'WPDDL_PRODUCTION' ) ) {
|
||||
$question_marks['template']['description'][1]['label'] = __( 'Creating templates with Layouts', 'wpcf' );
|
||||
}
|
||||
|
||||
return $question_marks;
|
||||
@@ -1,336 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/* Layouts, integrated, template missing*/
|
||||
'layouts-integrated-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Compatible',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no template layout for %POST-LABEL-SINGULAR% items.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-TEMPLATE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, template */
|
||||
'layouts-template' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Template_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'link',
|
||||
'label' => '%POST-LAYOUT-TEMPLATE%',
|
||||
'target' => '%POST-EDIT-LAYOUT-TEMPLATE%'
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, template */
|
||||
'views-template' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Template_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'link',
|
||||
'label' => '%POST-CONTENT-TEMPLATE-NAME%',
|
||||
'target' => '%POST-EDIT-CONTENT-TEMPLATE%'
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* For posts and pages we always show template file if it exists */
|
||||
'single-exists-for-posts-pages' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Type_Post_Or_Page',
|
||||
'Types_Helper_Condition_Single_Exists',
|
||||
'Types_Helper_Condition_Single_Has_Fields'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( '%POST-TEMPLATE-FILE%', 'wpcf' )
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, has template with missing fields. */
|
||||
'layouts-single-fields-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing',
|
||||
'Types_Helper_Condition_Single_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme’s template file %POST-TEMPLATE-FILE% for displaying %POST-LABEL-SINGULAR% items is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-TEMPLATE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, single.php exists, but layouts missing */
|
||||
'layouts-php-template-exists-layouts-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing',
|
||||
'Types_Helper_Condition_Single_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( '%POST-TEMPLATE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-TEMPLATE%',
|
||||
)
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
/* Layouts, template missing*/
|
||||
'layouts-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no template layout for %POST-LABEL-SINGULAR% items.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-TEMPLATE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Single Missing */
|
||||
'single-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Single_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme doesn’t have a template to display %POST-LABEL-PLURAL%.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'resolve-single-no-template',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Toolset plugins let you design templates for single items (%POST-LABEL-SINGULAR% pages) without
|
||||
writing PHP. Your templates will include all the fields that you need and your design.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn about creating templates with Toolset', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'creating-templates-with-toolset', 'popup' ),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Single, without Fields */
|
||||
'single-fields-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Single_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme’s template file for displaying %POST-LABEL-SINGULAR% items is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Resolve', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'resolve-single-no-fields',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Toolset plugins let you design templates for single items (%POST-LABEL-SINGULAR% pages),
|
||||
with all the fields that you need to display.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn about creating templates with Toolset', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'creating-templates-with-toolset', 'popup' ),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Single with Fields */
|
||||
'single-fields' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Single_Has_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( '%POST-TEMPLATE-FILE%', 'wpcf' )
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, has template with missing fields. */
|
||||
'views-single-fields-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Template_Missing',
|
||||
'Types_Helper_Condition_Single_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme’s template file %POST-TEMPLATE-FILE% for displaying %POST-LABEL-SINGULAR% items is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-CONTENT-TEMPLATE%',
|
||||
'label' => __( 'Create Content Template', 'wpcf' )
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, single.php exists, but views missing */
|
||||
'views-php-template-exists-views-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Template_Missing',
|
||||
'Types_Helper_Condition_Single_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( '%POST-TEMPLATE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-CONTENT-TEMPLATE%',
|
||||
'label' => __( 'Create Content Template', 'wpcf' )
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, template missing */
|
||||
'views-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Template_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no Content Template for %POST-LABEL-SINGULAR% items.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-CONTENT-TEMPLATE%',
|
||||
'label' => __( 'Create template', 'wpcf' )
|
||||
)
|
||||
),
|
||||
|
||||
),
|
||||
);
|
||||
@@ -1,138 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/* Views missing */
|
||||
'views-missing' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Views_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create View', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'create-view',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'To create a View for this content type, you need to have Views plugin installed. Views is part of the
|
||||
complete Toolset package for adding and displaying custom content.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn how Views work', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'how-views-work', 'popup' )
|
||||
),
|
||||
/*
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Free Toolset Trial', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'free-trial', 'popup' )
|
||||
)
|
||||
*/
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
/* Views, views missing */
|
||||
'views-views-missing' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Views_Missing',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button js-toolset-dashboard-create-view',
|
||||
'target' => '%POST-CREATE-VIEW%',
|
||||
'post_type' => '%POST-CREATE-VIEW-TYPE%',
|
||||
'redirect_url' => '%POST-CREATE-VIEW-REDIRECT-URL%',
|
||||
'label' => __( 'Create View', 'wpcf' ),
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
/* Views, views */
|
||||
'views-views' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Views_Exist',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => '%POST-VIEWS-LIST%',
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button js-toolset-dashboard-create-view',
|
||||
'target' => '%POST-CREATE-VIEW%',
|
||||
'post_type' => '%POST-CREATE-VIEW-TYPE%',
|
||||
'redirect_url' => '%POST-CREATE-VIEW-REDIRECT-URL%',
|
||||
'label' => __( 'Create View', 'wpcf' ),
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
/* Views Layouts, views missing */
|
||||
'views-layouts-views-missing' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Views_Views_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __(
|
||||
'Edit any layout and add a View cell to it, to display lists of %POST-LABEL-PLURAL%.', 'wpcf'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'target' => Types_Helper_Url::get_url( 'adding-views-to-layouts', 'table' ),
|
||||
'label' => __( 'Learn how', 'wpcf' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
/* Views Layouts, views */
|
||||
'views-layouts-views' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Views_Views_Exist'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => '%POST-VIEWS-LIST%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'target' => Types_Helper_Url::get_url( 'adding-views-to-layouts', 'table' ),
|
||||
'label' => __( 'How to add Views to layouts', 'wpcf' )
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
// Google Analytics
|
||||
// ?utm_source=typesplugin&utm_campaign=types&utm_medium=%CURRENT-SCREEN%&utm_term=EMPTY&utm_content=EMPTY
|
||||
|
||||
$urls = array(
|
||||
'learn-how-template' => 'https://wp-types.com/documentation/user-guides/benefits-of-templates-for-custom-types/',
|
||||
'learn-how-archive' => 'https://wp-types.com/documentation/user-guides/what-archives-are-and-why-they-are-so-important/',
|
||||
'learn-how-views' => 'https://wp-types.com/documentation/user-guides/learn-what-you-can-do-with-views/',
|
||||
'learn-how-forms' => 'https://wp-types.com/home/cred/',
|
||||
'learn-how-post-types' => 'https://wp-types.com/documentation/user-guides/create-a-custom-post-type/',
|
||||
'learn-how-fields' => 'https://wp-types.com/documentation/user-guides/using-custom-fields/',
|
||||
'learn-how-taxonomies' => 'https://wp-types.com/documentation/user-guides/create-custom-taxonomies/',
|
||||
'creating-templates-with-toolset' => 'https://wp-types.com/documentation/user-guides/learn-about-creating-templates-with-toolset/',
|
||||
'creating-templates-with-php' => 'https://wp-types.com/documentation/customizing-sites-using-php/creating-templates-single-custom-posts/',
|
||||
'creating-archives-with-toolset' => 'https://wp-types.com/documentation/user-guides/learn-about-creating-archives-with-toolset/',
|
||||
'creating-archives-with-php' => 'https://wp-types.com/documentation/customizing-sites-using-php/creating-templates-custom-post-type-archives/',
|
||||
'how-views-work' => 'https://wp-types.com/documentation/user-guides/learn-what-you-can-do-with-views/',
|
||||
'how-to-add-views-to-layouts' => 'https://wp-types.com/documentation/getting-started-with-toolset/adding-lists-of-contents/',
|
||||
'learn-views' => 'https://wp-types.com/documentation/user-guides/learn-what-you-can-do-with-views/',
|
||||
'how-cred-work' => 'https://wp-types.com/documentation/user-guides/learn-what-you-can-do-with-cred/',
|
||||
'how-to-add-forms-to-layouts' => 'https://wp-types.com/documentation/user-guides/creating-cred-forms/',
|
||||
'learn-cred' => 'https://wp-types.com/documentation/user-guides/learn-what-you-can-do-with-cred/',
|
||||
'free-trial' => 'https://wp-types.com/?add-to-cart=363363&buy_now=1',
|
||||
'adding-custom-fields-with-php' => 'https://wp-types.com/documentation/getting-started-with-toolset/creating-templates-for-displaying-post-types/',
|
||||
'themes-compatible-with-layouts' => 'https://wp-types.com/documentation/user-guides/layouts-theme-integration/#popular-integrated-themes',
|
||||
'layouts-integration-instructions' => 'https://wp-types.com/documentation/user-guides/layouts-theme-integration/#replacing-wp-loop-with-layouts',
|
||||
'adding-views-to-layouts' => 'https://wp-types.com/documentation/getting-started-with-toolset/adding-lists-of-contents/',
|
||||
'adding-forms-to-layouts' => 'https://wp-types.com/documentation/user-guides/adding-cred-forms-to-layouts/',
|
||||
'using-post-fields' => 'https://wp-types.com/user-guides/using-custom-fields/',
|
||||
'adding-fields' => 'https://wp-types.com/documentation/user-guides/using-custom-fields/#introduction-to-wordpress-custom-fields',
|
||||
'displaying-fields' => 'https://wp-types.com/documentation/getting-started-with-toolset/creating-templates-for-displaying-post-types/',
|
||||
'adding-user-fields' => 'https://wp-types.com/documentation/user-guides/user-fields/',
|
||||
'displaying-user-fields' => 'https://wp-types.com/documentation/user-guides/displaying-wordpress-user-fields/',
|
||||
'adding-term-fields' => 'https://wp-types.com/documentation/user-guides/term-fields/',
|
||||
'displaying-term-fields' => 'https://wp-types.com/documentation/user-guides/displaying-wordpress-term-fields/',
|
||||
'custom-post-types' => 'https://wp-types.com/documentation/user-guides/create-a-custom-post-type/',
|
||||
'custom-taxonomy' => 'https://wp-types.com/documentation/user-guides/create-custom-taxonomies/',
|
||||
'post-relationship' => 'https://wp-types.com/documentation/user-guides/creating-post-type-relationships/',
|
||||
'compare-toolset-php' => 'https://wp-types.com/landing/toolset-vs-php/',
|
||||
'types-fields-api' => 'https://wp-types.com/documentation/functions/',
|
||||
'parent-child' => 'https://wp-types.com/documentation/user-guides/many-to-many-post-relationship/',
|
||||
'custom-post-archives' => 'https://wp-types.com/documentation/user-guides/creating-wordpress-custom-post-archives/',
|
||||
'using-taxonomy' => 'https://wp-types.com/documentation/user-guides/create-custom-taxonomies/',
|
||||
'custom-taxonomy-archives' => 'https://wp-types.com/documentation/user-guides/creating-wordpress-custom-taxonomy-archives/',
|
||||
'repeating-fields-group' => 'https://wp-types.com/documentation/user-guides/creating-groups-of-repeating-fields-using-fields-tables/',
|
||||
'single-pages' => 'https://wp-types.com/documentation/user-guides/view-templates/',
|
||||
'content-templates' => 'https://wp-types.com/documentation/user-guides/view-templates/',
|
||||
'views-user-guide' => 'https://wp-types.com/documentation/getting-started-with-toolset/adding-lists-of-contents/',
|
||||
'wp-types' => 'https://wp-types.com/',
|
||||
'date-filters' => 'http://wp-types.com/documentation/user-guides/date-filters/',
|
||||
'getting-started-types' => 'https://wp-types.com/documentation/user-guides/getting-starting-with-types/',
|
||||
);
|
||||
|
||||
// Visual Composer
|
||||
if( defined( 'WPB_VC_VERSION' ) ) {
|
||||
$urls['learn-how-template'] = 'https://wp-types.com/documentation/user-guides/benefits-of-templates-for-custom-types-vc/';
|
||||
$urls['creating-templates-with-toolset'] = 'https://wp-types.com/documentation/user-guides/benefits-of-templates-for-custom-types-vc/';
|
||||
}
|
||||
// Beaver Builder
|
||||
else if( class_exists( 'FLBuilderLoader' ) ) {
|
||||
$urls['learn-how-template'] = 'https://wp-types.com/documentation/user-guides/benefits-of-templates-for-custom-types-bb/';
|
||||
$urls['creating-templates-with-toolset'] = 'https://wp-types.com/documentation/user-guides/benefits-of-templates-for-custom-types-bb/';
|
||||
}
|
||||
// Layouts
|
||||
else if( defined( 'WPDDL_DEVELOPMENT' ) || defined( 'WPDDL_PRODUCTION' ) ) {
|
||||
$urls['learn-how-template'] = 'https://wp-types.com/documentation/user-guides/benefits-of-templates-for-custom-types-layouts/';
|
||||
$urls['creating-templates-with-toolset'] = 'https://wp-types.com/documentation/user-guides/benefits-of-templates-for-custom-types-layouts/';
|
||||
}
|
||||
|
||||
return $urls;
|
||||
@@ -1,451 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/* Post Type with has_archive = false */
|
||||
'no-archive-support' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Archive_No_Support'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The archive is disabled for this post type.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'To enable, go to <a href="%POST-TYPE-EDIT-HAS-ARCHIVE%">Options</a> and mark "has_archive".', 'wpcf' )
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, integrated, Archive missing */
|
||||
'layouts-integrated-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Compatible',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no layout for the %POST-LABEL-PLURAL% archive.', 'wpcf' )
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, Archive */
|
||||
'layouts-archive' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Archive_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The layout for the %POST-LABEL-PLURAL% archive is "%POST-LAYOUT-ARCHIVE%".', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Edit layout', 'wpcf' ),
|
||||
'target' => '%POST-EDIT-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* For posts and pages we always show template file if it exists */
|
||||
'archive-exists-for-posts-pages' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Type_Post_Or_Page',
|
||||
'Types_Helper_Condition_Archive_Exists',
|
||||
'Types_Helper_Condition_Archive_Has_Fields'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme displays the %POST-LABEL-SINGULAR% archive using the file: %POST-ARCHIVE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, has template with missing fields. */
|
||||
'layouts-archive-fields-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing',
|
||||
'Types_Helper_Condition_Archive_No_Fields'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The %POST-LABEL-PLURAL% archive of your theme %POST-ARCHIVE-FILE% is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, single.php exists, but layouts missing */
|
||||
'layouts-php-archive-exists-layouts-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing',
|
||||
'Types_Helper_Condition_Archive_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme displays the %POST-LABEL-SINGULAR% archive using the file: %POST-ARCHIVE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, Archive missing */
|
||||
'layouts-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Archive_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no layout for the %POST-LABEL-PLURAL% archive.', 'wpcf' )
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Create archive', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Archive missing */
|
||||
'archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Archive_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme is missing the standard WordPress archive for %POST-LABEL-PLURAL%.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Resolve', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'resolve-no-archive',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Toolset plugins let you design archive pages without writing PHP. Your archives will include all
|
||||
the fields that you need and your design.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn about creating archives with Toolset', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'creating-archives-with-toolset', 'popup' ),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Archive without Fields */
|
||||
'archive-fields-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Archive_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The %POST-LABEL-PLURAL% archive of your theme is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Resolve', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'resolve-no-custom-fields',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Toolset plugins let you design archives with custom fields, without writing PHP.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn about creating archives with Toolset', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'creating-archives-with-toolset', 'popup' ),
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Archive Fields */
|
||||
'archive-fields' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Archive_Has_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme displays the %POST-LABEL-SINGULAR% archive using the file: %POST-ARCHIVE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, has template with missing fields. */
|
||||
'views-archive-fields-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Archive_Missing',
|
||||
'Types_Helper_Condition_Archive_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The %POST-LABEL-PLURAL% archive of your theme %POST-ARCHIVE-FILE% is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'target' => '%POST-CREATE-VIEWS-ARCHIVE%',
|
||||
'label' => __( 'Create archive', 'wpcf' )
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, archive.php exists, but views missing */
|
||||
'views-php-archive-exists-views-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Archive_Missing',
|
||||
'Types_Helper_Condition_Archive_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme displays the %POST-LABEL-SINGULAR% archive using the file: %POST-ARCHIVE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'target' => '%POST-CREATE-VIEWS-ARCHIVE%',
|
||||
'label' => __( 'Create archive', 'wpcf' )
|
||||
)
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
/* Views, template missing */
|
||||
'views-archive-missing' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Archive_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no WordPress Archive for %POST-LABEL-PLURAL%.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'target' => '%POST-CREATE-VIEWS-ARCHIVE%',
|
||||
'label' => __( 'Create archive', 'wpcf' )
|
||||
)
|
||||
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, archive */
|
||||
'views-archive' => array(
|
||||
'type' => 'archive',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Archive_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The WordPress Archive for %POST-LABEL-PLURAL% is "%POST-VIEWS-ARCHIVE%"', 'wpcf' )
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit the %POST-LABEL-PLURAL% archive', 'wpcf' ),
|
||||
'target' => '%POST-ARCHIVE-PERMALINK%'
|
||||
),
|
||||
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Edit WordPress Archive', 'wpcf' ),
|
||||
'target' => '%POST-EDIT-VIEWS-ARCHIVE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/* CRED missing */
|
||||
'cred-missing' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Cred_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create Form', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'create-form',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'To create a form for front-end content submission and editing, you need to have CRED plugin installed.
|
||||
CRED is part of the complete Toolset package for adding and displaying custom content.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn how CRED forms work', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'how-cred-work', 'popup' )
|
||||
),
|
||||
/*
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Free Toolset Trial', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'free-trial', 'popup' )
|
||||
),
|
||||
*/
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* CRED, forms missing */
|
||||
'cred-forms-missing' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Cred_Forms_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-FORM%',
|
||||
'label' => __( 'Create form', 'wpcf' )
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
/* CRED, forms */
|
||||
'cred-forms' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Cred_Active',
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Cred_Forms_Exist'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => '%POST-FORMS-LIST%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-FORM%',
|
||||
'label' => __( 'Create form', 'wpcf' )
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
/* CRED & Layouts, forms missing */
|
||||
'cred-layouts-forms-missing' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Cred_Forms_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __(
|
||||
'You can create forms for front-end submission and editing of %POST-LABEL-PLURAL%.', 'wpcf'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'target' => Types_Helper_Url::get_url( 'adding-forms-to-layouts', 'table' ),
|
||||
'label' => __( 'Learn how', 'wpcf' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
/* CRED & Layouts, forms exists */
|
||||
'cred-layouts-forms' => array(
|
||||
'type' => 'forms',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Cred_Forms_Exist'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => '%POST-FORMS-LIST%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'target' => Types_Helper_Url::get_url( 'adding-forms-to-layouts', 'table' ),
|
||||
'label' => __( 'How to add forms to layouts', 'wpcf' )
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
@@ -1,85 +0,0 @@
|
||||
<?php
|
||||
$question_marks = array(
|
||||
'template' => array(
|
||||
'id' => 'template',
|
||||
'title' => __( 'Template', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'A template displays single-item pages with your design and fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-template', 'tooltip' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
'archive' => array(
|
||||
'id' => 'archive',
|
||||
'title' => __( 'Archive', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'An archive is the standard list that WordPress produces for content.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-archive', 'tooltip' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
'views' => array(
|
||||
'id' => 'views',
|
||||
'title' => __( 'Views', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Views are custom lists of content, which you can display anywhere in the site.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-views', 'tooltip' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
'forms' => array(
|
||||
'id' => 'forms',
|
||||
'title' => __( 'Forms', 'wpcf' ),
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Forms allow to create and edit content from the site’s front-end.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn more', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'learn-how-forms', 'tooltip' )
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// Visual Composer
|
||||
if( defined( 'WPB_VC_VERSION' ) ) {
|
||||
$question_marks['template']['description'][1]['label'] = __( 'Creating templates with Visual Composer', 'wpcf' );
|
||||
}
|
||||
// Beaver Builder
|
||||
else if( class_exists( 'FLBuilderLoader' ) ) {
|
||||
$question_marks['template']['description'][1]['label'] = __( 'Creating templates with Beaver Builder', 'wpcf' );
|
||||
}
|
||||
// Layouts
|
||||
else if( defined( 'WPDDL_DEVELOPMENT' ) || defined( 'WPDDL_PRODUCTION' ) ) {
|
||||
$question_marks['template']['description'][1]['label'] = __( 'Creating templates with Layouts', 'wpcf' );
|
||||
}
|
||||
|
||||
return $question_marks;
|
||||
@@ -1,432 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/* Layouts, integrated, template missing*/
|
||||
'layouts-integrated-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Compatible',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no template layout for %POST-LABEL-SINGULAR% items.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-TEMPLATE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, template */
|
||||
'layouts-template' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Template_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The template layout for %POST-LABEL-SINGULAR% items is "%POST-LAYOUT-TEMPLATE%".', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Edit template', 'wpcf' ),
|
||||
'target' => '%POST-EDIT-LAYOUT-TEMPLATE%'
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* For posts and pages we always show template file if it exists */
|
||||
'single-exists-for-posts-pages' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Type_Post_Or_Page',
|
||||
'Types_Helper_Condition_Single_Exists',
|
||||
'Types_Helper_Condition_Single_Has_Fields'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme displays single %POST-LABEL-SINGULAR% pages using the template file: %POST-TEMPLATE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, has template with missing fields. */
|
||||
'layouts-single-fields-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing',
|
||||
'Types_Helper_Condition_Single_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme’s template file %POST-TEMPLATE-FILE% for displaying %POST-LABEL-SINGULAR% items is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-TEMPLATE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Layouts, single.php exists, but layouts missing */
|
||||
'layouts-php-template-exists-layouts-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing',
|
||||
'Types_Helper_Condition_Single_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme displays single %POST-LABEL-SINGULAR% pages using the template file: %POST-TEMPLATE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-TEMPLATE%',
|
||||
)
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
/* Layouts, template missing*/
|
||||
'layouts-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Layouts_Template_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no template layout for %POST-LABEL-SINGULAR% items.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Create template', 'wpcf' ),
|
||||
'target' => '%POST-CREATE-LAYOUT-TEMPLATE%',
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Single Missing */
|
||||
'single-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Single_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme doesn’t have a template to display %POST-LABEL-PLURAL%.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Resolve', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'resolve-single-no-template',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Toolset plugins let you design templates for single items (%POST-LABEL-SINGULAR% pages) without
|
||||
writing PHP. Your templates will include all the fields that you need and your design.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn about creating templates with Toolset', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'creating-templates-with-toolset', 'popup' ),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Single, without Fields */
|
||||
'single-fields-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Single_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme’s template file for displaying %POST-LABEL-SINGULAR% items is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => array(
|
||||
'default' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'post-edit' => __( 'Visit this %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button-primary types-button',
|
||||
'label' => __( 'Resolve', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'resolve-single-no-fields',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Toolset plugins let you design templates for single items (%POST-LABEL-SINGULAR% pages),
|
||||
with all the fields that you need to display.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn about creating templates with Toolset', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'creating-templates-with-toolset', 'popup' ),
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* No Views, No Layouts, Single with Fields */
|
||||
'single-fields' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Missing',
|
||||
'Types_Helper_Condition_Single_Has_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme displays single %POST-LABEL-SINGULAR% pages using the template file: %POST-TEMPLATE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, has template with missing fields. */
|
||||
'views-single-fields-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Template_Missing',
|
||||
'Types_Helper_Condition_Single_No_Fields',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme’s template file %POST-TEMPLATE-FILE% for displaying %POST-LABEL-SINGULAR% items is missing custom fields.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'target' => '%POST-CREATE-CONTENT-TEMPLATE%',
|
||||
'label' => __( 'Create Content Template', 'wpcf' )
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
/* Views, single.php exists, but views missing */
|
||||
'views-php-template-exists-views-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Template_Missing',
|
||||
'Types_Helper_Condition_Single_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'Your theme displays single %POST-LABEL-SINGULAR% pages using the template file: %POST-TEMPLATE-FILE%', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'target' => '%POST-CREATE-CONTENT-TEMPLATE%',
|
||||
'label' => __( 'Create Content Template', 'wpcf' )
|
||||
)
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
/* Views, template missing */
|
||||
'views-template-missing' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'priority' => 'important',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Template_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'There is no Content Template for %POST-LABEL-SINGULAR% items.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button-primary types-button',
|
||||
'target' => '%POST-CREATE-CONTENT-TEMPLATE%',
|
||||
'label' => __( 'Create Content Template', 'wpcf' )
|
||||
)
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
/* Views, template */
|
||||
'views-template' => array(
|
||||
'type' => 'template',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Template_Exists'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'The Content Template for %POST-LABEL-PLURAL% is "%POST-CONTENT-TEMPLATE-NAME%"', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => array(
|
||||
'default' => __( 'Visit example %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
'post-edit' => __( 'Visit this %POST-LABEL-SINGULAR%', 'wpcf' ),
|
||||
),
|
||||
'target' => '%POST-PERMALINK%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Edit Content Template', 'wpcf' ),
|
||||
'target' => '%POST-EDIT-CONTENT-TEMPLATE%'
|
||||
),
|
||||
),
|
||||
|
||||
),
|
||||
);
|
||||
@@ -1,134 +0,0 @@
|
||||
<?php
|
||||
return array(
|
||||
/* Views missing */
|
||||
'views-missing' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Views_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'dialog',
|
||||
'class' => 'button',
|
||||
'label' => __( 'Create View', 'wpcf' ),
|
||||
'dialog' => array(
|
||||
'id' => 'create-view',
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __( 'To create a View for this content type, you need to have Views plugin installed. Views is part of the
|
||||
complete Toolset package for adding and displaying custom content.', 'wpcf' )
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Learn how Views work', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'how-views-work', 'popup' )
|
||||
),
|
||||
/*
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'label' => __( 'Free Toolset Trial', 'wpcf' ),
|
||||
'target' => Types_Helper_Url::get_url( 'free-trial', 'popup' )
|
||||
)
|
||||
*/
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
),
|
||||
|
||||
/* Views, views missing */
|
||||
'views-views-missing' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Views_Missing',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-VIEW%',
|
||||
'label' => __( 'Create View', 'wpcf' )
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
/* Views, views */
|
||||
'views-views' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Missing',
|
||||
'Types_Helper_Condition_Views_Views_Exist',
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => '%POST-VIEWS-LIST%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'class' => 'button',
|
||||
'target' => '%POST-CREATE-VIEW%',
|
||||
'label' => __( 'Create View', 'wpcf' )
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
/* Views Layouts, views missing */
|
||||
'views-layouts-views-missing' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Views_Views_Missing'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => __(
|
||||
'Edit any layout and add a View cell to it, to display lists of %POST-LABEL-PLURAL%.', 'wpcf'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'target' => Types_Helper_Url::get_url( 'adding-views-to-layouts', 'table' ),
|
||||
'label' => __( 'Learn how', 'wpcf' )
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
/* Views Layouts, views */
|
||||
'views-layouts-views' => array(
|
||||
'type' => 'views',
|
||||
|
||||
'conditions'=> array(
|
||||
'Types_Helper_Condition_Layouts_Active',
|
||||
'Types_Helper_Condition_Views_Views_Exist'
|
||||
),
|
||||
|
||||
'description' => array(
|
||||
array(
|
||||
'type' => 'paragraph',
|
||||
'content' => '%POST-VIEWS-LIST%'
|
||||
),
|
||||
array(
|
||||
'type' => 'link',
|
||||
'external' => true,
|
||||
'target' => Types_Helper_Url::get_url( 'adding-views-to-layouts', 'table' ),
|
||||
'label' => __( 'How to add Views to layouts', 'wpcf' )
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
@@ -1,171 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is meant for very generic functions that should be allways available, PHP compatibility fixes and so on.
|
||||
*
|
||||
* Do not let it grow too much and make sure to wrap each function in !function_exists() condition.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
|
||||
if( !function_exists( 'wpcf_getpost' ) ) {
|
||||
|
||||
/**
|
||||
* Safely retrieve a key from $_POST variable.
|
||||
*
|
||||
* This is a wrapper for wpcf_getarr(). See that for more information.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @param null|array $valid
|
||||
*
|
||||
* @return mixed
|
||||
* @since 1.9
|
||||
*/
|
||||
function wpcf_getpost( $key, $default = '', $valid = null ) {
|
||||
return wpcf_getarr( $_POST, $key, $default, $valid );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( !function_exists( 'wpcf_getget' ) ) {
|
||||
|
||||
/**
|
||||
* Safely retrieve a key from $_GET variable.
|
||||
*
|
||||
* This is a wrapper for wpcf_getarr(). See that for more information.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @param null|array $valid
|
||||
*
|
||||
* @return mixed
|
||||
* @since 1.9
|
||||
*/
|
||||
function wpcf_getget( $key, $default = '', $valid = null ) {
|
||||
return wpcf_getarr( $_GET, $key, $default, $valid );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( !function_exists( 'wpcf_getarr' ) ) {
|
||||
|
||||
/**
|
||||
* Safely retrieve a key from given array (meant for $_POST, $_GET, etc).
|
||||
*
|
||||
* Checks if the key is set in the source array. If not, default value is returned. Optionally validates against array
|
||||
* of allowed values and returns default value if the validation fails.
|
||||
*
|
||||
* @param array $source The source array.
|
||||
* @param string|int $key The key to be retrieved from the source array.
|
||||
* @param mixed $default Default value to be returned if key is not set or the value is invalid. Optional.
|
||||
* Default is empty string.
|
||||
* @param null|array $valid If an array is provided, the value will be validated against it's elements.
|
||||
*
|
||||
* @return mixed The value of the given key or $default.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
function wpcf_getarr( &$source, $key, $default = '', $valid = null ) {
|
||||
if ( is_array( $source ) && array_key_exists( $key, $source ) ) {
|
||||
$val = $source[ $key ];
|
||||
if ( is_array( $valid ) && ! in_array( $val, $valid ) ) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return $val;
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( !function_exists( 'wpcf_ensarr' ) ) {
|
||||
|
||||
/**
|
||||
* Ensure that a variable is an array.
|
||||
*
|
||||
* @param mixed $array The original value.
|
||||
* @param array $default Default value to use when no array is provided. This one should definitely be an array,
|
||||
* otherwise the function doesn't make much sense.
|
||||
*
|
||||
* @return array The original array or a default value if no array is provided.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
function wpcf_ensarr( $array, $default = array() ) {
|
||||
return ( is_array( $array ) ? $array : $default );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( !function_exists( 'wpcf_wraparr' ) ) {
|
||||
|
||||
/**
|
||||
* Wrap a variable value in an array if it's not array already.
|
||||
*
|
||||
* @param mixed $input
|
||||
*
|
||||
* @return array
|
||||
* @since 1.9.1
|
||||
*/
|
||||
function wpcf_wraparr( $input ) {
|
||||
return ( is_array( $input ) ? $input : array( $input ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( !function_exists( 'wpcf_getnest' ) ) {
|
||||
|
||||
/**
|
||||
* Get a value from nested associative array.
|
||||
*
|
||||
* This function will try to traverse a nested associative array by the set of keys provided.
|
||||
*
|
||||
* E.g. if you have $source = array( 'a' => array( 'b' => array( 'c' => 'my_value' ) ) ) and want to reach 'my_value',
|
||||
* you need to write: $my_value = wpcf_getnest( $source, array( 'a', 'b', 'c' ) );
|
||||
*
|
||||
* @param mixed|array $source The source array.
|
||||
* @param string[] $keys Keys which will be used to access the final value.
|
||||
* @param null|mixed $default Default value to return when the keys cannot be followed.
|
||||
*
|
||||
* @return mixed|null Value in the nested structure defined by keys or default value.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
function wpcf_getnest( &$source, $keys = array(), $default = null ) {
|
||||
|
||||
$current_value = $source;
|
||||
|
||||
// For detecting if a value is missing in a sub-array, we'll use this temporary object.
|
||||
// We cannot just use $default on every level of the nesting, because if $default is an
|
||||
// (possibly nested) array itself, it might mess with the value retrieval in an unexpected way.
|
||||
$missing_value = new stdClass();
|
||||
|
||||
while( ! empty( $keys ) ) {
|
||||
$current_key = array_shift( $keys );
|
||||
$is_last_key = empty( $keys );
|
||||
|
||||
$current_value = wpcf_getarr( $current_value, $current_key, $missing_value );
|
||||
|
||||
if ( $is_last_key ) {
|
||||
// Apply given default value.
|
||||
if( $missing_value === $current_value ) {
|
||||
return $default;
|
||||
} else {
|
||||
return $current_value;
|
||||
}
|
||||
} elseif ( ! is_array( $current_value ) ) {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Checkbox field type.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Field_Type_Definition_Checkbox extends Types_Field_Type_Definition_Singular {
|
||||
|
||||
|
||||
/**
|
||||
* Types_Field_Type_Definition_Checkbox constructor.
|
||||
*
|
||||
* @param array $args
|
||||
* @since 2.0
|
||||
*/
|
||||
public function __construct( $args ) {
|
||||
parent::__construct( Types_Field_Type_Definition_Factory::CHECKBOX, $args );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
protected function sanitize_field_definition_array_type_specific( $definition_array ) {
|
||||
|
||||
$definition_array['type'] = Types_Field_Type_Definition_Factory::CHECKBOX;
|
||||
|
||||
$definition_array = $this->sanitize_element_isset( $definition_array, 'display', 'db', array( 'db', 'value' ), 'data' );
|
||||
$definition_array = $this->sanitize_element_isset( $definition_array, 'display_value_selected', '', null, 'data' );
|
||||
$definition_array = $this->sanitize_element_isset( $definition_array, 'display_value_not_selected', '', null, 'data' );
|
||||
$definition_array = $this->sanitize_element_isset( $definition_array, 'save_empty', 'no', array( 'yes', 'no' ), 'data' );
|
||||
|
||||
$set_value = wpcf_getnest( $definition_array, array( 'data', 'set_value' ) );
|
||||
if( !is_string( $set_value ) && !is_numeric( $set_value ) ) {
|
||||
$set_value = '1';
|
||||
}
|
||||
$definition_array['data']['set_value'] = $set_value;
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class Types_Field_Type_Definition_Checkboxes extends Types_Field_Type_Definition_Singular {
|
||||
|
||||
public function __construct( $args ) {
|
||||
parent::__construct( Types_Field_Type_Definition_Factory::CHECKBOXES, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function sanitize_field_definition_array_type_specific( $definition_array ) {
|
||||
|
||||
$definition_array['type'] = Types_Field_Type_Definition_Factory::CHECKBOXES;
|
||||
|
||||
$definition_array = $this->sanitize_element_isset( $definition_array, 'save_empty', 'no', array( 'yes', 'no' ), 'data' );
|
||||
|
||||
$options = wpcf_ensarr( wpcf_getnest( $definition_array, array( 'data', 'options' ) ) );
|
||||
|
||||
foreach( $options as $key => $option ) {
|
||||
$options[ $key ] = $this->sanitize_single_option( $option );
|
||||
}
|
||||
|
||||
$definition_array['data']['options'] = $options;
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sanitize single checkboxes option definition.
|
||||
*
|
||||
* @param array $option
|
||||
* @return array Sanitized option.
|
||||
* @since 2.1
|
||||
*/
|
||||
private function sanitize_single_option( $option ) {
|
||||
$option = $this->sanitize_element_isset( wpcf_ensarr( $option ), 'set_value' );
|
||||
$option = $this->sanitize_element_isset( $option, 'title', $option['set_value'] );
|
||||
$option = $this->sanitize_element_isset( $option, 'display', 'db', array( 'db', 'value' ) );
|
||||
$option = $this->sanitize_element_isset( $option, 'display_value_selected' );
|
||||
$option = $this->sanitize_element_isset( $option, 'display_value_not_selected' );
|
||||
return $option;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class Types_Field_Type_Definition_Date extends Types_Field_Type_Definition {
|
||||
|
||||
/**
|
||||
* Types_Field_Type_Definition_Date constructor.
|
||||
*
|
||||
* @param array $args
|
||||
*/
|
||||
public function __construct( $args ) {
|
||||
parent::__construct( Types_Field_Type_Definition_Factory::DATE, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
public function sanitize_field_definition_array_type_specific( $definition_array ) {
|
||||
|
||||
$definition_array['type'] = Types_Field_Type_Definition_Factory::DATE;
|
||||
|
||||
$definition_array = $this->sanitize_element_isset( $definition_array, 'date_and_time', 'date', array( 'date', 'and_time' ), 'data' );
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Numeric field type.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
final class Types_Field_Type_Definition_Numeric extends Types_Field_Type_Definition {
|
||||
|
||||
|
||||
/**
|
||||
* Types_Field_Type_Definition_Numeric constructor.
|
||||
*
|
||||
* @param array $args
|
||||
*/
|
||||
public function __construct( $args ) {
|
||||
parent::__construct( Types_Field_Type_Definition_Factory::NUMERIC, $args );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function sanitize_field_definition_array_type_specific( $definition_array ) {
|
||||
|
||||
$definition_array['type'] = Types_Field_Type_Definition_Factory::NUMERIC;
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add the 'number' validation if it was not already there, and activate it.
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
protected function sanitize_numeric_validation( $definition_array ) {
|
||||
|
||||
// Get the original setting or a default one.
|
||||
$validation_setting = wpcf_ensarr(
|
||||
wpcf_getnest( $definition_array, array( 'data', 'validate', 'number' ) ),
|
||||
array( 'active' => true, 'message' => __( 'Please enter numeric data', 'wpcf' ) )
|
||||
);
|
||||
|
||||
// Force the activation of this validation.
|
||||
$validation_setting['active'] = true;
|
||||
|
||||
// Store the setting.
|
||||
$definition_array['data']['validate']['number'] = $validation_setting;
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class Types_Field_Type_Definition_Radio extends Types_Field_Type_Definition_Singular {
|
||||
|
||||
public function __construct( $args ) {
|
||||
parent::__construct( Types_Field_Type_Definition_Factory::RADIO, $args );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function sanitize_field_definition_array_type_specific( $definition_array ) {
|
||||
|
||||
$definition_array['type'] = Types_Field_Type_Definition_Factory::RADIO;
|
||||
|
||||
$options = wpcf_ensarr( wpcf_getnest( $definition_array, array( 'data', 'options' ) ) );
|
||||
|
||||
foreach( $options as $key => $option ) {
|
||||
if( 'default' == $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options[ $key ] = $this->sanitize_single_option( $option );
|
||||
}
|
||||
|
||||
$default_option = wpcf_getarr( $options, 'default' );
|
||||
if( !is_string( $default_option ) || !array_key_exists( $default_option, $options ) ) {
|
||||
$default_option = 'no-default';
|
||||
}
|
||||
$options['default'] = $default_option;
|
||||
|
||||
$definition_array['data']['options'] = $options;
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sanitize single checkboxes option definition.
|
||||
*
|
||||
* @param array $option
|
||||
* @return array Sanitized option.
|
||||
* @since 2.1
|
||||
*/
|
||||
private function sanitize_single_option( $option ) {
|
||||
$option = $this->sanitize_element_isset( wpcf_ensarr( $option ), 'value' );
|
||||
$option = $this->sanitize_element_isset( $option, 'title', $option['value'] );
|
||||
$option = $this->sanitize_element_isset( $option, 'display_value', $option['value'] );
|
||||
return $option;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
final class Types_Field_Type_Definition_Select extends Types_Field_Type_Definition_Singular {
|
||||
|
||||
|
||||
public function __construct( $args ) {
|
||||
parent::__construct( Types_Field_Type_Definition_Factory::SELECT, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function sanitize_field_definition_array_type_specific( $definition_array ) {
|
||||
|
||||
$definition_array['type'] = Types_Field_Type_Definition_Factory::SELECT;
|
||||
|
||||
$options = wpcf_ensarr( wpcf_getnest( $definition_array, array( 'data', 'options' ) ) );
|
||||
|
||||
foreach( $options as $key => $option ) {
|
||||
if( 'default' == $key ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options[ $key ] = $this->sanitize_single_option( $option );
|
||||
}
|
||||
|
||||
$default_option = wpcf_getarr( $options, 'default' );
|
||||
if( !is_string( $default_option ) || !array_key_exists( $default_option, $options ) ) {
|
||||
$default_option = 'no-default';
|
||||
}
|
||||
$options['default'] = $default_option;
|
||||
|
||||
$definition_array['data']['options'] = $options;
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sanitize single checkboxes option definition.
|
||||
*
|
||||
* @param array $option
|
||||
* @return array Sanitized option.
|
||||
* @since 2.1
|
||||
*/
|
||||
private function sanitize_single_option( $option ) {
|
||||
$option = $this->sanitize_element_isset( wpcf_ensarr( $option ), 'value' );
|
||||
$option = $this->sanitize_element_isset( $option, 'title', $option['value'] );
|
||||
return $option;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Field type definition for single-value only fields.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Field_Type_Definition_Singular extends Types_Field_Type_Definition {
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return bool
|
||||
*/
|
||||
public function can_be_repetitive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,556 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Abstract representation of a field group (without defined type).
|
||||
*
|
||||
* Descendants of this class allways must be instantiated through appropriate factory class inheriting
|
||||
* from Types_Field_Group_Factory.
|
||||
*
|
||||
* Any method that permanently changes any group data needs to call execute_group_updated_action() afterwards.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
abstract class Types_Field_Group {
|
||||
|
||||
/**
|
||||
* Stores the slugs of the fields that belong to this group, as a comma separated list.
|
||||
*/
|
||||
const POSTMETA_FIELD_SLUGS_LIST = '_wp_types_group_fields';
|
||||
|
||||
|
||||
const FIELD_SLUG_DELIMITER = ',';
|
||||
|
||||
|
||||
/**
|
||||
* @var WP_Post Post object that represents the field group.
|
||||
*/
|
||||
private $post;
|
||||
|
||||
|
||||
/**
|
||||
* Types_Field_Group constructor.
|
||||
*
|
||||
* Note that it is protected - inheriting classes have to implement an override that should, additionally, check
|
||||
* if the post has correct type.
|
||||
*
|
||||
* @param WP_Post $field_group_post Post object that represents the field group.
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function __construct( $field_group_post ) {
|
||||
if( ! $field_group_post instanceof WP_Post ) {
|
||||
throw new InvalidArgumentException( 'First argument is not a post.' );
|
||||
}
|
||||
$this->post = $field_group_post;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return WPCF_Field_Definition_Factory Field definition factory of the correct type.
|
||||
*/
|
||||
protected abstract function get_field_definition_factory();
|
||||
|
||||
|
||||
/**
|
||||
* @return WP_Post Post object representing the field group.
|
||||
*/
|
||||
protected function get_post() {
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int ID of the field group.
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->get_post()->ID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string Unique name (post slug) of the field group.
|
||||
*/
|
||||
public function get_slug() {
|
||||
return sanitize_title( $this->get_post()->post_name );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string Field group description. Sanitized as a text field.
|
||||
*/
|
||||
public function get_description() {
|
||||
return sanitize_text_field( $this->get_post()->post_content );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Note that for displaying group name to the user you should use get_display_name() instead.
|
||||
*
|
||||
* @return string Field group title.
|
||||
*/
|
||||
public function get_name() {
|
||||
return sanitize_text_field( $this->get_post()->post_title );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get group name as it should be displayed to the user.
|
||||
*
|
||||
* Handles string translation if applicable.
|
||||
*/
|
||||
public function get_display_name() {
|
||||
return wpcf_translate(
|
||||
sprintf( 'group %d name', $this->get_id() ),
|
||||
$this->get_name()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null|bool $value If boolean value is provided, the group will be activated or deactivated accordingly.
|
||||
* For null, nothing happens.
|
||||
* @return bool True if the field group is active, false if deactivated.
|
||||
* @since 1.9
|
||||
*/
|
||||
public function is_active( $value = null ) {
|
||||
|
||||
if( null !== $value ) {
|
||||
$this->update_post( array( 'post_status' => ( $value ? 'publish' : 'draft' ) ) );
|
||||
}
|
||||
|
||||
$post = $this->get_post();
|
||||
return ( $post->post_status == 'publish' ? true : false );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string Status of the underlying post. Limited to 'publish'|'draft' (default).
|
||||
*/
|
||||
public function get_post_status() {
|
||||
return ( $this->is_active() ? 'publish' : 'draft' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int ID of the user who edited the field group last.
|
||||
*/
|
||||
public function get_author() {
|
||||
$post = $this->get_post();
|
||||
return (int) $post->post_author;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* $group['meta_box_context'] = 'normal';
|
||||
$group['meta_box_priority'] = 'high';
|
||||
$group['filters_association'] = get_post_meta( $post->ID, '_wp_types_group_filters_association', true );
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Change name of the field group.
|
||||
*
|
||||
* Do not confuse with the title. *All* changes of the name must happen through this method, otherwise
|
||||
* unexpected behaviour of the Types_Field_Group_Factory can occur.
|
||||
*
|
||||
* @param string $value New value of the post name. Note that it may be further modified by WordPress before saving.
|
||||
*/
|
||||
public function set_name( $value ) {
|
||||
$result = $this->update_post( array( 'post_name' => sanitize_title( $value ) ) );
|
||||
if( true == $result ) {
|
||||
do_action( 'wpcf_field_group_renamed', $value, $this );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the underlying post object.
|
||||
*
|
||||
* Also refreshes the stored post object and fires an action notifying about the change.
|
||||
*
|
||||
* @param array $args Arguments for wp_update_post(). ID doesn't have to be provided, it will be added automatically.
|
||||
* @return bool True on success, false otherwise.
|
||||
* @since 2.1
|
||||
*/
|
||||
private function update_post( $args ) {
|
||||
|
||||
$args = array_merge( array( 'ID' => $this->get_id() ), $args );
|
||||
|
||||
$updated_post_id = wp_update_post( $args );
|
||||
|
||||
if( 0 !== $updated_post_id ) {
|
||||
// Refresh the post object
|
||||
$this->post = WP_Post::get_instance( $updated_post_id );
|
||||
|
||||
$this->execute_group_updated_action();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string The underlying post type of the post representing the field group.
|
||||
*/
|
||||
public function get_post_type() {
|
||||
$post = $this->get_post();
|
||||
return $post->post_type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var null|array Array of field slugs that belong to this field group, or null if it was not loaded from database yet.
|
||||
*/
|
||||
private $field_slugs = null;
|
||||
|
||||
|
||||
/**
|
||||
* Check if a field slug is valid and can be stored in the database.
|
||||
*
|
||||
* @param string $field_slug
|
||||
* @return bool True if the slug is valid.
|
||||
*/
|
||||
public function is_valid_field_slug( $field_slug ) {
|
||||
return !empty( $field_slug ) && is_string( $field_slug ) && ( sanitize_title( $field_slug ) == $field_slug );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if an array of field slugs is valid.
|
||||
*
|
||||
* @param array|mixed $field_slugs
|
||||
* @return bool True if an array of valid field slugs was provided.
|
||||
*/
|
||||
protected function validate_field_slugs( $field_slugs ) {
|
||||
if( !is_array( $field_slugs ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Every element needs to be valid
|
||||
if( count( $field_slugs ) != count ( array_filter( $field_slugs, array( $this, 'is_valid_field_slug' ) ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array Slugs of fields that belong to this field group, or empty array when database doesn't contain
|
||||
* valid data.
|
||||
*
|
||||
* Consider using get_field_definitions() instead.
|
||||
*/
|
||||
public function get_field_slugs() {
|
||||
if( null == $this->field_slugs ) {
|
||||
$field_slug_list = get_post_meta( $this->get_id(), self::POSTMETA_FIELD_SLUGS_LIST, true );
|
||||
|
||||
if( !is_string( $field_slug_list ) ) {
|
||||
$field_slug_list = '';
|
||||
}
|
||||
|
||||
$field_slugs = explode( self::FIELD_SLUG_DELIMITER, $field_slug_list );
|
||||
|
||||
// Remove empty slugs
|
||||
foreach( $field_slugs as $key => $slug ) {
|
||||
if( empty( $slug ) ) {
|
||||
unset( $field_slugs[ $key ] );
|
||||
}
|
||||
}
|
||||
|
||||
$this->field_slugs = $this->validate_field_slugs( $field_slugs ) ? $field_slugs : array();
|
||||
}
|
||||
return $this->field_slugs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all existing definitions of fields that belong to this group.
|
||||
*
|
||||
* @return WPCF_Field_Definition[]
|
||||
*/
|
||||
public function get_field_definitions() {
|
||||
$slugs = $this->get_field_slugs();
|
||||
$field_definitions = array();
|
||||
$factory = $this->get_field_definition_factory();
|
||||
foreach( $slugs as $slug ) {
|
||||
$field_definition = $factory->load_field_definition( $slug );
|
||||
if( null != $field_definition && $field_definition->is_under_types_control() ) {
|
||||
$field_definitions[] = $field_definition;
|
||||
}
|
||||
}
|
||||
return $field_definitions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the set of field slugs that belong to this field group.
|
||||
*
|
||||
* @param array $field_slugs Array of valid field slugs.
|
||||
* @return bool True if the database was updated successfully, false otherwise.
|
||||
*/
|
||||
protected function set_field_slugs( $field_slugs ) {
|
||||
if( !$this->validate_field_slugs( $field_slugs ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->field_slugs = $field_slugs;
|
||||
|
||||
$field_slug_list = implode( self::FIELD_SLUG_DELIMITER, $field_slugs );
|
||||
|
||||
$updated = update_post_meta( $this->get_id(), self::POSTMETA_FIELD_SLUGS_LIST, $field_slug_list );
|
||||
|
||||
$this->execute_group_updated_action();
|
||||
|
||||
return ( $updated != false );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove field definition from this group.
|
||||
*
|
||||
* @param WPCF_Field_Definition $field_definition
|
||||
* @return bool
|
||||
*/
|
||||
public function remove_field_definition( $field_definition ) {
|
||||
|
||||
if( ! ( $field_definition instanceof WPCF_Field_Definition ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$field_slugs = $this->get_field_slugs();
|
||||
|
||||
$slug_to_remove = $field_definition->get_slug();
|
||||
$key = array_search( $slug_to_remove, $field_slugs );
|
||||
if( $key !== false ) {
|
||||
unset( $field_slugs[ $key ] );
|
||||
$is_success = $this->set_field_slugs( $field_slugs );
|
||||
} else {
|
||||
$is_success = true;
|
||||
}
|
||||
|
||||
return $is_success;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Associate a field definition with this group.
|
||||
*
|
||||
* @param WPCF_Field_Definition $field_definition
|
||||
* @return bool True on success, false otherwise.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function add_field_definition( $field_definition ) {
|
||||
|
||||
if( ! ( $field_definition instanceof WPCF_Field_Definition ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$field_slugs = $this->get_field_slugs();
|
||||
|
||||
$slug_to_add = $field_definition->get_slug();
|
||||
if( !in_array( $slug_to_add, $field_slugs ) ) {
|
||||
$field_slugs[] = $slug_to_add;
|
||||
$is_success = $this->set_field_slugs( $field_slugs );
|
||||
} else {
|
||||
$is_success = true;
|
||||
}
|
||||
|
||||
return $is_success;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a string is contained within the field group definition.
|
||||
*
|
||||
* Searches in ID, slug, title and description. Case insensitive.
|
||||
*
|
||||
* @param string $search_string String to look for.
|
||||
* @return bool True if found.
|
||||
*/
|
||||
public function is_match( $search_string ) {
|
||||
return (
|
||||
Types_Utils::is_string_match( $search_string, $this->get_id() )
|
||||
|| Types_Utils::is_string_match( $search_string, $this->get_slug() )
|
||||
|| Types_Utils::is_string_match( $search_string, $this->get_name() )
|
||||
|| Types_Utils::is_string_match( $search_string, $this->get_display_name() )
|
||||
|| Types_Utils::is_string_match( $search_string, $this->get_description() )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function contains_field_definition( $field_definition ) {
|
||||
if( $field_definition instanceof WPCF_Field_Definition ) {
|
||||
return in_array( $field_definition, $this->get_field_definitions() );
|
||||
} elseif( is_string( $field_definition ) ) {
|
||||
return in_array( $field_definition, $this->get_field_slugs() );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the wpcf_group_updated action.
|
||||
*
|
||||
* Needs to be called after each (permanent) change to a group.
|
||||
*/
|
||||
public function execute_group_updated_action() {
|
||||
|
||||
/**
|
||||
* Executed after a group has been updated in the database.
|
||||
*
|
||||
* @param int $id Group ID.
|
||||
* @param Types_Field_Group $group The group object.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
do_action( 'wpcf_group_updated', $this->get_id(), $this );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var null|false|string[] Cache for get_assigned_to_types().
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
private $assigned_to_types = null;
|
||||
|
||||
|
||||
/**
|
||||
* Fetch all post types assigned to this group from the database.
|
||||
*
|
||||
* @return false|string[] Array of post type slugs (empty array meaning "all post types") or false if not applicable.
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function fetch_assigned_to_types() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all post types assigned to this group from the database.
|
||||
*
|
||||
* Cached.
|
||||
*
|
||||
* @return false|string[] Array of post type slugs (empty array meaning "all post types") or false if not applicable.
|
||||
* @since 2.1
|
||||
*/
|
||||
public function get_assigned_to_types() {
|
||||
if( null === $this->assigned_to_types ) {
|
||||
$this->assigned_to_types = $this->fetch_assigned_to_types();
|
||||
}
|
||||
|
||||
return $this->assigned_to_types;
|
||||
}
|
||||
|
||||
|
||||
private $assigned_to_items = null;
|
||||
|
||||
|
||||
/**
|
||||
* Fetch all items that are using this group.
|
||||
*
|
||||
* @return array|false Array of items (whose type varies upon the field domain) or false if not applicable.
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function fetch_assigned_to_items() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all items that are using this group.
|
||||
*
|
||||
* Cached.
|
||||
*
|
||||
* @return array|false Array of items (whose type varies upon the field domain) or false if not applicable.
|
||||
* @since 2.1
|
||||
*/
|
||||
public function get_assigned_to_items() {
|
||||
if( null === $this->assigned_to_items ) {
|
||||
$this->fetch_assigned_to_items();
|
||||
}
|
||||
|
||||
return $this->assigned_to_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keys in the group export object.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
const XML_ID = 'ID';
|
||||
const XML_SLUG = 'slug';
|
||||
const XML_NAME = 'post_title';
|
||||
const XML_TYPE = 'post_type';
|
||||
const XML_DESCRIPTION = 'post_content';
|
||||
const XML_IS_ACTIVE = 'is_active';
|
||||
const XML_LEGACY_EXCERPT = 'post_excerpt';
|
||||
const XML_LEGACY_POST_STATUS = 'post_status';
|
||||
const XML_META_SECTION = 'meta';
|
||||
|
||||
|
||||
/**
|
||||
* Get raw data of this field group to be exported.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function get_export_fields() {
|
||||
|
||||
$field_slugs = $this->get_field_slugs();
|
||||
$field_slugs = implode( ',', $field_slugs );
|
||||
|
||||
$result = array(
|
||||
self::XML_ID => $this->get_id(),
|
||||
self::XML_SLUG => $this->get_slug(),
|
||||
self::XML_NAME => $this->get_name(),
|
||||
self::XML_TYPE => $this->get_post_type(),
|
||||
self::XML_IS_ACTIVE => $this->is_active(),
|
||||
self::XML_LEGACY_EXCERPT => '',
|
||||
self::XML_LEGACY_POST_STATUS => $this->get_post_status(),
|
||||
self::XML_META_SECTION => array(
|
||||
self::POSTMETA_FIELD_SLUGS_LIST => $field_slugs
|
||||
),
|
||||
WPCF_AUTHOR => $this->get_author()
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get array of keys that should be used for generating field group checksum.
|
||||
*
|
||||
* @return string[]
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function get_keys_for_export_checksum() {
|
||||
return array(
|
||||
self::XML_NAME, self::XML_TYPE, self::XML_LEGACY_EXCERPT, self::XML_LEGACY_POST_STATUS, self::XML_IS_ACTIVE,
|
||||
WPCF_AUTHOR, self::XML_META_SECTION
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an export object for this group, containing complete information including checksum and annotation.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
public function get_export_object() {
|
||||
|
||||
$data = $this->get_export_fields();
|
||||
|
||||
$ie_controller = Types_Import_Export::get_instance();
|
||||
|
||||
$data = $ie_controller->add_checksum_to_object( $data, $this->get_keys_for_export_checksum() );
|
||||
|
||||
$data = $ie_controller->annotate_object( $data, $this->get_name(), $this->get_slug() );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,325 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Abstract factory for field group classes.
|
||||
*
|
||||
* It ensures that each field group is instantiated only once and it keeps returning that one instance.
|
||||
*
|
||||
* Note: Cache is indexed by slugs, so if a field group can change it's slug, it is necessary to do
|
||||
* an 'wpcf_field_group_renamed' action immediately after renaming.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
abstract class Types_Field_Group_Factory {
|
||||
|
||||
|
||||
/**
|
||||
* Singleton parent.
|
||||
*
|
||||
* @link http://stackoverflow.com/questions/3126130/extending-singletons-in-php
|
||||
* @return Types_Field_Group_Factory Instance of calling class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
static $instances = array();
|
||||
$called_class = get_called_class();
|
||||
if( !isset( $instances[ $called_class ] ) ) {
|
||||
$instances[ $called_class ] = new $called_class();
|
||||
}
|
||||
return $instances[ $called_class ];
|
||||
}
|
||||
|
||||
|
||||
protected function __construct() {
|
||||
add_action( 'wpcf_field_group_renamed', array( $this, 'field_group_renamed' ), 10, 2 );
|
||||
}
|
||||
|
||||
|
||||
final private function __clone() { }
|
||||
|
||||
|
||||
/**
|
||||
* For a given field domain, return the appropriate field group factory instance.
|
||||
*
|
||||
* @param string $domain Valid field domain
|
||||
* @return Types_Field_Group_Factory
|
||||
* @since 2.1
|
||||
*/
|
||||
public static function get_factory_by_domain( $domain ) {
|
||||
switch( $domain ) {
|
||||
case Types_Field_Utils::DOMAIN_POSTS:
|
||||
return Types_Field_Group_Post_Factory::get_instance();
|
||||
case Types_Field_Utils::DOMAIN_USERS:
|
||||
return Types_Field_Group_User_Factory::get_instance();
|
||||
case Types_Field_Utils::DOMAIN_TERMS:
|
||||
return Types_Field_Group_Term_Factory::get_instance();
|
||||
default:
|
||||
throw new InvalidArgumentException( 'Invalid field domain.' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string Post type that holds information about this field group type.
|
||||
*/
|
||||
abstract public function get_post_type();
|
||||
|
||||
|
||||
/**
|
||||
* @return string Name of the class that represents this field group type (and that will be instantiated). It must
|
||||
* be a child of Types_Field_Group.
|
||||
*/
|
||||
abstract protected function get_field_group_class_name();
|
||||
|
||||
|
||||
/**
|
||||
* Get a post object that represents a field group.
|
||||
*
|
||||
* @param int|string|WP_Post $field_group Numeric ID of the post, post slug or a post object.
|
||||
*
|
||||
* @return null|WP_Post Requested post object when the post exists and has correct post type. Null otherwise.
|
||||
*/
|
||||
final protected function get_post( $field_group ) {
|
||||
|
||||
$fg_post = null;
|
||||
|
||||
// http://stackoverflow.com/questions/2559923/shortest-way-to-check-if-a-variable-contains-positive-integer-using-php
|
||||
if ( is_numeric( $field_group ) && ( $field_group == (int) $field_group ) && ( (int) $field_group > 0 ) ) {
|
||||
$fg_post = WP_Post::get_instance( $field_group );
|
||||
} else if ( is_string( $field_group ) ) {
|
||||
$query = new WP_Query( array( 'post_type' => $this->get_post_type(), 'name' => $field_group, 'posts_per_page' => 1 ) );
|
||||
if( $query->have_posts() ) {
|
||||
$fg_post = $query->get_posts();
|
||||
$fg_post = $fg_post[0];
|
||||
}
|
||||
} else {
|
||||
$fg_post = $field_group;
|
||||
}
|
||||
|
||||
if( $fg_post instanceof WP_Post && $this->get_post_type() == $fg_post->post_type ) {
|
||||
return $fg_post;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var array Array of field group instances for this post type, indexed by names (post slugs).
|
||||
*/
|
||||
private $field_groups = array();
|
||||
|
||||
|
||||
/**
|
||||
* @param string $field_group_name Name of the field group.
|
||||
*
|
||||
* @return null|Types_Field_Group Field group instance or null if it's not cached.
|
||||
*/
|
||||
private function get_from_cache( $field_group_name ) {
|
||||
if( defined( 'TYPES_DISABLE_CACHE' ) && TYPES_DISABLE_CACHE ) {
|
||||
// disable caching
|
||||
return null;
|
||||
}
|
||||
return wpcf_getarr( $this->field_groups, $field_group_name, null );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save a field group instance to cache.
|
||||
*
|
||||
* @param Types_Field_Group $field_group
|
||||
*/
|
||||
private function save_to_cache( $field_group ) {
|
||||
if( defined( 'TYPES_DISABLE_CACHE' ) && TYPES_DISABLE_CACHE ) {
|
||||
// disable caching
|
||||
return;
|
||||
}
|
||||
$this->field_groups[ $field_group->get_slug() ] = $field_group;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove field group instance from cache.
|
||||
* @param string $field_group_name
|
||||
*/
|
||||
private function clear_from_cache( $field_group_name ) {
|
||||
unset( $this->field_groups[ $field_group_name ] );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a field group instance.
|
||||
*
|
||||
* @param int|string|WP_Post $field_group_source Post ID of the field group, it's name or a WP_Post object.
|
||||
*
|
||||
* @return null|Types_Field_Group Field group or null if it can't be loaded.
|
||||
*/
|
||||
final public function load_field_group( $field_group_source ) {
|
||||
|
||||
$post = null;
|
||||
|
||||
// If we didn't get a field group name, we first need to get the post so we can look into the cache.
|
||||
if( !is_string( $field_group_source ) ) {
|
||||
$post = $this->get_post( $field_group_source );
|
||||
if( null == $post ) {
|
||||
// There is no such post (or has wrong type).
|
||||
return null;
|
||||
}
|
||||
$field_group_name = $post->post_name;
|
||||
} else {
|
||||
$field_group_name = $field_group_source;
|
||||
}
|
||||
|
||||
// Try to get an existing instance.
|
||||
$field_group = $this->get_from_cache( $field_group_name );
|
||||
if( null != $field_group ) {
|
||||
return $field_group;
|
||||
}
|
||||
|
||||
// We might already have the post by now.
|
||||
if( null == $post ) {
|
||||
$post = $this->get_post( $field_group_source );
|
||||
}
|
||||
|
||||
// There is no such post (or has wrong type).
|
||||
if( null == $post ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create new field group instance
|
||||
try {
|
||||
$class_name = $this->get_field_group_class_name();
|
||||
$field_group = new $class_name( $post );
|
||||
} catch( Exception $e ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->save_to_cache( $field_group );
|
||||
return $field_group;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update cache after a field group is renamed.
|
||||
*
|
||||
* @param string $original_name The old name of the field group.
|
||||
* @param Types_Field_Group $field_group The field group involved, with already updated name.
|
||||
*/
|
||||
public function field_group_renamed( $original_name, $field_group ) {
|
||||
if( $field_group->get_post_type() == $this->get_post_type() ) {
|
||||
$this->clear_from_cache( $original_name );
|
||||
$this->save_to_cache( $field_group );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new field group.
|
||||
*
|
||||
* @param string $name Sanitized field group name. Note that the final name may change when new post is inserted.
|
||||
* @param string $title Field group title.
|
||||
* @param string $status Only 'draft'|'publish' are expected. Groups with the 'draft' status will appear as deactivated.
|
||||
*
|
||||
* @return null|Types_Field_Group The new field group or null on error.
|
||||
*/
|
||||
final public function create_field_group( $name, $title = '', $status = 'draft' ) {
|
||||
|
||||
if( sanitize_title( $name ) != $name ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$title = wp_strip_all_tags( $title );
|
||||
|
||||
$post_id = wp_insert_post( array(
|
||||
'post_type' => $this->get_post_type(),
|
||||
'post_name' => $name,
|
||||
'post_title' => empty( $title ) ? $name : $title,
|
||||
'post_status' => $status,
|
||||
) );
|
||||
|
||||
if( 0 == $post_id ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Store the mandatory postmeta, just to be safe. I'm not sure about invariants here.
|
||||
update_post_meta( $post_id, Types_Field_Group::POSTMETA_FIELD_SLUGS_LIST, '' );
|
||||
|
||||
$field_group = $this->load_field_group( $post_id );
|
||||
|
||||
$field_group->execute_group_updated_action();
|
||||
|
||||
return $field_group;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get field groups based on query arguments.
|
||||
*
|
||||
* @param array $query_args Optional. Arguments for the WP_Query that will be applied on the underlying posts.
|
||||
* Post type query is added automatically.
|
||||
* Additional arguments are allowed:
|
||||
* - 'types_search': String for extended search. See WPCF_Field_Group::is_match() for details.
|
||||
* - 'is_active' bool: If defined, only active/inactive field groups will be returned.
|
||||
*
|
||||
* @return Types_Field_Group[]
|
||||
* @since 1.9
|
||||
*/
|
||||
public function query_groups( $query_args = array() ) {
|
||||
|
||||
// Read specific arguments
|
||||
$search_string = wpcf_getarr( $query_args, 'types_search' );
|
||||
$is_active = wpcf_getarr( $query_args, 'is_active', null );
|
||||
|
||||
// Query posts
|
||||
$query_args = array_merge( $query_args, array( 'post_type' => $this->get_post_type(), 'posts_per_page' => -1 ) );
|
||||
|
||||
// Group's "activeness" is defined by the post status.
|
||||
if( null !== $is_active ) {
|
||||
unset( $query_args['is_active'] );
|
||||
$query_args['post_status'] = ( $is_active ? 'publish' : 'draft' );
|
||||
}
|
||||
|
||||
$query = new WP_Query( $query_args );
|
||||
$posts = $query->get_posts();
|
||||
|
||||
// Transform posts into Types_Field_Group
|
||||
$all_groups = array();
|
||||
foreach( $posts as $post ) {
|
||||
$field_group = $this->load_field_group( $post );
|
||||
if( null != $field_group ) {
|
||||
$all_groups[] = $field_group;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter groups by the search string.
|
||||
$selected_groups = array();
|
||||
if( empty( $search_string ) ) {
|
||||
$selected_groups = $all_groups;
|
||||
} else {
|
||||
/** @var Types_Field_Group $group */
|
||||
foreach ( $all_groups as $group ) {
|
||||
if ( $group->is_match( $search_string ) ) {
|
||||
$selected_groups[] = $group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $selected_groups;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a map of all field group slugs to their display names.
|
||||
*
|
||||
* @return string[]
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_group_slug_to_displayname_map() {
|
||||
$groups = $this->query_groups();
|
||||
$group_names = array();
|
||||
foreach( $groups as $group ) {
|
||||
$group_names[ $group->get_slug() ] = $group->get_display_name();
|
||||
}
|
||||
return $group_names;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Post field group.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Field_Group_Post extends Types_Field_Group {
|
||||
|
||||
|
||||
const POST_TYPE = 'wp-types-group';
|
||||
|
||||
/**
|
||||
* Postmeta that contains a comma-separated list of post type slugs where this field group is assigned.
|
||||
*
|
||||
* Note: There might be empty items in the list: ",,,post-type-slug,," Make sure to avoid those.
|
||||
*
|
||||
* Note: Empty value means "all groups". There also may be legacy value "all" with the same meaning.
|
||||
*
|
||||
* @since unknown
|
||||
*/
|
||||
const POSTMETA_POST_TYPE_LIST = '_wp_types_group_post_types';
|
||||
|
||||
|
||||
/**
|
||||
* @param WP_Post $field_group_post Post object representing a post field group.
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct( $field_group_post ) {
|
||||
parent::__construct( $field_group_post );
|
||||
if( self::POST_TYPE != $field_group_post->post_type ) {
|
||||
throw new InvalidArgumentException( 'incorrect post type' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return WPCF_Field_Definition_Factory Field definition factory of the correct type.
|
||||
*/
|
||||
protected function get_field_definition_factory() {
|
||||
return WPCF_Field_Definition_Factory_Post::get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a post type to the group
|
||||
* @param $post_type
|
||||
*/
|
||||
public function assign_post_type( $post_type ) {
|
||||
$post_types = $this->get_assigned_to_types();
|
||||
$post_types[] = $post_type;
|
||||
|
||||
$this->store_post_types( $post_types );
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores an array of post types as list in database
|
||||
*
|
||||
* @param array $post_types
|
||||
*/
|
||||
protected function store_post_types( $post_types ) {
|
||||
// validate post types
|
||||
foreach( $post_types as $type ) {
|
||||
if( empty( $type ) || ! get_post_type( $type ) )
|
||||
unset( $post_types[$type] );
|
||||
}
|
||||
|
||||
$post_types = empty( $post_types )
|
||||
? ''
|
||||
: implode( ',', $post_types );
|
||||
|
||||
update_post_meta( $this->get_id(), self::POSTMETA_POST_TYPE_LIST, $post_types );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function fetch_assigned_to_types() {
|
||||
$db_assigned_to = get_post_meta( $this->get_id(), self::POSTMETA_POST_TYPE_LIST, true );
|
||||
|
||||
// in old types version we store "all"
|
||||
if ( 'all' == $db_assigned_to ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Keep your eyes open on storing values,
|
||||
// This is needed because legacy code produces values like ,,,,a-post-type,,
|
||||
$db_assigned_to = trim( $db_assigned_to, ',' );
|
||||
|
||||
// empty means all post types are selected
|
||||
if ( empty( $db_assigned_to ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// we have selected post types
|
||||
return explode( ',', $db_assigned_to );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return WP_Post[] Individual posts using this group.
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function fetch_assigned_to_items() {
|
||||
$assigned_posts = $this->get_assigned_to_types();
|
||||
|
||||
if( empty( $assigned_posts ) ) {
|
||||
$assigned_posts = array( 'all' );
|
||||
}
|
||||
|
||||
$items = get_posts(
|
||||
array(
|
||||
'post_type' => $assigned_posts,
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => -1,
|
||||
)
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the backend edit link.
|
||||
*
|
||||
* @return string
|
||||
* @since 2.1
|
||||
*/
|
||||
public function get_edit_link() {
|
||||
return admin_url() . '/admin.php?page=wpcf-edit&group_id=' . $this->get_id();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Factory for the Types_Field_Group_Post class.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Field_Group_Post_Factory extends Types_Field_Group_Factory {
|
||||
|
||||
|
||||
/**
|
||||
* @return Types_Field_Group_Post_Factory
|
||||
*/
|
||||
public static function get_instance() {
|
||||
return parent::get_instance();
|
||||
}
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
//add_action( 'wpcf_group_updated', array( $this, 'on_group_updated' ), 10, 2 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a field group instance.
|
||||
*
|
||||
* @param int|string|WP_Post $field_group Post ID of the field group, it's name or a WP_Post object.
|
||||
*
|
||||
* @return null|Types_Field_Group_Term Field group or null if it can't be loaded.
|
||||
*/
|
||||
public static function load( $field_group ) {
|
||||
// we cannot use self::get_instance here, because of low PHP requirements and missing get_called_class function
|
||||
// we have a fallback class for get_called_class but that scans files by debug_backtrace and return 'self'
|
||||
// instead of Types_Field_Group_Term_Factory like the original get_called_class() function does
|
||||
// ends in an error because of parents (abstract) $var = new self();
|
||||
return Types_Field_Group_Post_Factory::get_instance()->load_field_group( $field_group );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new field group.
|
||||
*
|
||||
* @param string $name Sanitized field group name. Note that the final name may change when new post is inserted.
|
||||
* @param string $title Field group title.
|
||||
*
|
||||
* @return null|Types_Field_Group The new field group or null on error.
|
||||
*/
|
||||
public static function create( $name, $title = '', $status = 'draft' ) {
|
||||
// we cannot use self::get_instance here, because of low PHP requirements and missing get_called_class function
|
||||
// we have a fallback class for get_called_class but that scans files by debug_backtrace and return 'self'
|
||||
// instead of Types_Field_Group_Term_Factory like the original get_called_class() function does
|
||||
// ends in an error because of parents (abstract) $var = new self();
|
||||
return Types_Field_Group_Post_Factory::get_instance()->create_field_group( $name, $title, $status );
|
||||
}
|
||||
|
||||
|
||||
public function get_post_type() {
|
||||
return Types_Field_Group_Post::POST_TYPE;
|
||||
}
|
||||
|
||||
|
||||
protected function get_field_group_class_name() {
|
||||
return 'Types_Field_Group_Post';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Term field group.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
class Types_Field_Group_Term extends Types_Field_Group {
|
||||
|
||||
|
||||
const POST_TYPE = 'wp-types-term-group';
|
||||
|
||||
|
||||
/**
|
||||
* Key for postmeta that holds slugs of taxonomies associated with this group. This is a "plural" postmeta,
|
||||
* each record contains one slug.
|
||||
*/
|
||||
const POSTMETA_ASSOCIATED_TAXONOMY = '_wp_types_associated_taxonomy';
|
||||
|
||||
|
||||
/**
|
||||
* Types_Field_Group_Term constructor.
|
||||
*
|
||||
* @param WP_Post $field_group_post Post object representing a term field group.
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct( $field_group_post ) {
|
||||
parent::__construct( $field_group_post );
|
||||
if( self::POST_TYPE != $field_group_post->post_type ) {
|
||||
throw new InvalidArgumentException( 'incorrect post type' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return WPCF_Field_Definition_Factory Field definition factory of the correct type.
|
||||
*/
|
||||
protected function get_field_definition_factory() {
|
||||
return WPCF_Field_Definition_Factory_Term::get_instance();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get taxonomies that are associated with this field group.
|
||||
*
|
||||
* @return string[] Taxonomy slugs. Empty array means that this group should be displayed with all taxonomies.
|
||||
*/
|
||||
public function get_associated_taxonomies() {
|
||||
$postmeta = get_post_meta( $this->get_id(), self::POSTMETA_ASSOCIATED_TAXONOMY, false );
|
||||
|
||||
// Survive empty or whitespace taxonomy slugs (skip them). They are invalid values but
|
||||
// if we have only them, we need to return an empty array to keep the group displayed everywhere.
|
||||
foreach( $postmeta as $index => $taxonomy_slug ) {
|
||||
$taxonomy_slug = trim( $taxonomy_slug );
|
||||
if( empty( $taxonomy_slug ) ) {
|
||||
unset( $postmeta[ $index ] );
|
||||
}
|
||||
}
|
||||
|
||||
return wpcf_ensarr( $postmeta );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Quickly determine whether given taxonomy is associated with this group.
|
||||
*
|
||||
* @param string $taxonomy_slug
|
||||
* @return bool
|
||||
*/
|
||||
public function has_associated_taxonomy( $taxonomy_slug ) {
|
||||
$taxonomies = $this->get_associated_taxonomies();
|
||||
return ( empty( $taxonomies ) || in_array( $taxonomy_slug, $taxonomies ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove association with a single taxonomy from the database.
|
||||
*
|
||||
* @param string $taxonomy_slug Slug of the taxonomy.
|
||||
*/
|
||||
private function remove_associated_taxonomy( $taxonomy_slug ) {
|
||||
if( empty( $taxonomy_slug ) ) {
|
||||
return;
|
||||
}
|
||||
delete_post_meta( $this->get_id(), self::POSTMETA_ASSOCIATED_TAXONOMY, $taxonomy_slug );
|
||||
$this->execute_group_updated_action();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an association with a single taxonomy to the database.
|
||||
*
|
||||
* @param string $taxonomy_slug Slug of the taxonomy. If empty or not sanitized, the function does nothing.
|
||||
*/
|
||||
private function add_associated_taxonomy( $taxonomy_slug ) {
|
||||
if( empty( $taxonomy_slug ) || $taxonomy_slug != sanitize_title( $taxonomy_slug )) {
|
||||
return;
|
||||
}
|
||||
add_post_meta( $this->get_id(), self::POSTMETA_ASSOCIATED_TAXONOMY, $taxonomy_slug );
|
||||
$this->execute_group_updated_action();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the set of taxonomies associated with this field group.
|
||||
*
|
||||
* @param string[] $taxonomy_slugs Array of (sanitized) taxonomy slugs.
|
||||
*/
|
||||
public function update_associated_taxonomies( $taxonomy_slugs ) {
|
||||
$current_taxonomies = $this->get_associated_taxonomies();
|
||||
|
||||
// Remove taxonomies that are associated but shouldn't be.
|
||||
$to_remove = array_diff( $current_taxonomies, $taxonomy_slugs );
|
||||
foreach( $to_remove as $taxonomy_slug ) {
|
||||
$this->remove_associated_taxonomy( $taxonomy_slug );
|
||||
}
|
||||
|
||||
// Add taxonomies that aren't associated but should be.
|
||||
$to_add = array_diff( $taxonomy_slugs, $current_taxonomies );
|
||||
foreach( $to_add as $taxonomy_slug ) {
|
||||
$this->add_associated_taxonomy( $taxonomy_slug );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Element name for a single associated taxonomy. */
|
||||
const XML_ASSOCIATED_TAXONOMY = 'taxonomy';
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* Add term field group-specific information to the export object.
|
||||
*
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function get_export_fields() {
|
||||
|
||||
$data = parent::get_export_fields();
|
||||
|
||||
// Array of slugs of associated taxonomies.
|
||||
$associated_taxonomy_data = implode( ',', $this->get_associated_taxonomies() );
|
||||
|
||||
// parent::XML_META_SECTION is ensured by the parent method
|
||||
$data[ parent::XML_META_SECTION ][ self::POSTMETA_ASSOCIATED_TAXONOMY ] = $associated_taxonomy_data;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Factory for the Types_Field_Group_Term class.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
class Types_Field_Group_Term_Factory extends Types_Field_Group_Factory {
|
||||
|
||||
|
||||
/**
|
||||
* @return Types_Field_Group_Term_Factory
|
||||
*/
|
||||
public static function get_instance() {
|
||||
return parent::get_instance();
|
||||
}
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
add_action( 'wpcf_group_updated', array( $this, 'on_group_updated' ), 10, 2 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a field group instance.
|
||||
*
|
||||
* @param int|string|WP_Post $field_group Post ID of the field group, it's name or a WP_Post object.
|
||||
*
|
||||
* @return null|Types_Field_Group_Term Field group or null if it can't be loaded.
|
||||
*/
|
||||
public static function load( $field_group ) {
|
||||
// we cannot use self::get_instance here, because of low PHP requirements and missing get_called_class function
|
||||
// we have a fallback class for get_called_class but that scans files by debug_backtrace and return 'self'
|
||||
// instead of Types_Field_Group_Term_Factory like the original get_called_class() function does
|
||||
// ends in an error because of parents (abstract) $var = new self();
|
||||
return Types_Field_Group_Term_Factory::get_instance()->load_field_group( $field_group );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new field group.
|
||||
*
|
||||
* @param string $name Sanitized field group name. Note that the final name may change when new post is inserted.
|
||||
* @param string $title Field group title.
|
||||
*
|
||||
* @return null|Types_Field_Group The new field group or null on error.
|
||||
*/
|
||||
public static function create( $name, $title = '' ) {
|
||||
// we cannot use self::get_instance here, because of low PHP requirements and missing get_called_class function
|
||||
// we have a fallback class for get_called_class but that scans files by debug_backtrace and return 'self'
|
||||
// instead of Types_Field_Group_Term_Factory like the original get_called_class() function does
|
||||
// ends in an error because of parents (abstract) $var = new self();
|
||||
return Types_Field_Group_Term_Factory::get_instance()->create_field_group( $name, $title );
|
||||
}
|
||||
|
||||
|
||||
public function get_post_type() {
|
||||
return Types_Field_Group_Term::POST_TYPE;
|
||||
}
|
||||
|
||||
|
||||
protected function get_field_group_class_name() {
|
||||
return 'Types_Field_Group_Term';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var null|Types_Field_Group_Term[][] Cache for the get_groups_by_taxonomies() method.
|
||||
*/
|
||||
private $taxonomy_assignment_cache = null;
|
||||
|
||||
|
||||
/**
|
||||
* Clears the cache for taxonomy assignemnts.
|
||||
* It is only used for testing purposes.
|
||||
*
|
||||
* @since 2.2
|
||||
* @deprecated deprecated since version 2.2
|
||||
*/
|
||||
public function clear_taxonomy_assignment_cache() {
|
||||
$this->taxonomy_assignment_cache = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Produce a list of all taxonomies with groups that belong to them.
|
||||
*
|
||||
* @return Types_Field_Group_Term[][] Associative array where keys are taxonomy slugs and values are arrays of field
|
||||
* groups that are associated with those taxonomies.
|
||||
*/
|
||||
public function get_groups_by_taxonomies() {
|
||||
if( null == $this->taxonomy_assignment_cache ) {
|
||||
$groups = $this->query_groups();
|
||||
$taxonomies = get_taxonomies();
|
||||
|
||||
$this->taxonomy_assignment_cache = array();
|
||||
foreach( $taxonomies as $taxonomy ) {
|
||||
$taxonomy_slug = $taxonomy;
|
||||
$groups_for_taxonomy = array();
|
||||
|
||||
foreach( $groups as $group ) {
|
||||
if( $group instanceof Types_Field_Group_Term
|
||||
&& $group->is_active()
|
||||
&& $group->has_associated_taxonomy( $taxonomy_slug )
|
||||
) {
|
||||
$groups_for_taxonomy[] = $group;
|
||||
}
|
||||
}
|
||||
|
||||
$this->taxonomy_assignment_cache[ $taxonomy_slug ] = $groups_for_taxonomy;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->taxonomy_assignment_cache;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get array of groups that are associated with given taxonomy.
|
||||
*
|
||||
* @param string $taxonomy_slug Slug of the taxonomy
|
||||
*
|
||||
* @return Types_Field_Group_Term[] Associated term field groups.
|
||||
*/
|
||||
public function get_groups_by_taxonomy( $taxonomy_slug ) {
|
||||
$groups_by_taxonomies = $this->get_groups_by_taxonomies();
|
||||
return wpcf_ensarr( wpcf_getarr( $groups_by_taxonomies, $taxonomy_slug ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This needs to be executed whenever a term group is updated.
|
||||
*
|
||||
* Hooked into the wpcf_group_updated action.
|
||||
* Erases cache for the get_groups_by_taxonomies() method.
|
||||
*
|
||||
* @param int $group_id Ignored
|
||||
* @param Types_Field_Group $group Field group that has been just updated.
|
||||
*/
|
||||
public function on_group_updated( /** @noinspection PhpUnusedParameterInspection */ $group_id, $group ) {
|
||||
if( $group instanceof Types_Field_Group_Term ) {
|
||||
$this->taxonomy_assignment_cache = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* User field group.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Field_Group_User extends Types_Field_Group {
|
||||
|
||||
|
||||
const POST_TYPE = 'wp-types-user-group';
|
||||
|
||||
|
||||
/**
|
||||
* @param WP_Post $field_group_post Post object representing a user field group.
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct( $field_group_post ) {
|
||||
parent::__construct( $field_group_post );
|
||||
if( self::POST_TYPE != $field_group_post->post_type ) {
|
||||
throw new InvalidArgumentException( 'incorrect post type' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return WPCF_Field_Definition_Factory Field definition factory of the correct type.
|
||||
*/
|
||||
protected function get_field_definition_factory() {
|
||||
return WPCF_Field_Definition_Factory_User::get_instance();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Factory for the Types_Field_Group_User class.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Field_Group_User_Factory extends Types_Field_Group_Factory {
|
||||
|
||||
|
||||
/**
|
||||
* @return Types_Field_Group_User_Factory
|
||||
*/
|
||||
public static function get_instance() {
|
||||
return parent::get_instance();
|
||||
}
|
||||
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
//add_action( 'wpcf_group_updated', array( $this, 'on_group_updated' ), 10, 2 );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a field group instance.
|
||||
*
|
||||
* @param int|string|WP_Post $field_group Post ID of the field group, it's name or a WP_Post object.
|
||||
*
|
||||
* @return null|Types_Field_Group_User Field group or null if it can't be loaded.
|
||||
*/
|
||||
public static function load( $field_group ) {
|
||||
// we cannot use self::get_instance here, because of low PHP requirements and missing get_called_class function
|
||||
// we have a fallback class for get_called_class but that scans files by debug_backtrace and return 'self'
|
||||
// instead of Types_Field_Group_Term_Factory like the original get_called_class() function does
|
||||
// ends in an error because of parents (abstract) $var = new self();
|
||||
return Types_Field_Group_User_Factory::get_instance()->load_field_group( $field_group );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create new field group.
|
||||
*
|
||||
* @param string $name Sanitized field group name. Note that the final name may change when new post is inserted.
|
||||
* @param string $title Field group title.
|
||||
*
|
||||
* @return null|Types_Field_Group The new field group or null on error.
|
||||
*/
|
||||
public static function create( $name, $title = '' ) {
|
||||
// we cannot use self::get_instance here, because of low PHP requirements and missing get_called_class function
|
||||
// we have a fallback class for get_called_class but that scans files by debug_backtrace and return 'self'
|
||||
// instead of Types_Field_Group_Term_Factory like the original get_called_class() function does
|
||||
// ends in an error because of parents (abstract) $var = new self();
|
||||
return Types_Field_Group_User_Factory::get_instance()->create_field_group( $name, $title );
|
||||
}
|
||||
|
||||
|
||||
public function get_post_type() {
|
||||
return Types_Field_Group_User::POST_TYPE;
|
||||
}
|
||||
|
||||
|
||||
protected function get_field_group_class_name() {
|
||||
return 'Types_Field_Group_User';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Field type definition.
|
||||
*
|
||||
* This represents a single field type like "email", "audio", "checkbox" and so on. This class must be instantiated
|
||||
* exclusively through Types_Field_Type_Definition_Factory.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Field_Type_Definition {
|
||||
|
||||
|
||||
/**
|
||||
* @var string Slug of the registered field type.
|
||||
*/
|
||||
private $field_type_slug;
|
||||
|
||||
|
||||
/**
|
||||
* @var string Name of the field type that can be displayed to the user.
|
||||
*/
|
||||
private $display_name;
|
||||
|
||||
|
||||
/**
|
||||
* @var string Field description entered by the user.
|
||||
*/
|
||||
private $description;
|
||||
|
||||
|
||||
/**
|
||||
* @var array Arguments defining the field type. Can contain some legacy values.
|
||||
*/
|
||||
private $args;
|
||||
|
||||
|
||||
/**
|
||||
* Types_Field_Type_Definition constructor.
|
||||
*
|
||||
* @param string $field_type_slug Field type slug.
|
||||
* @param array $args Additional array of arguments which should contain at least 'display_name' (or 'title')
|
||||
* and 'description' elements, but omitting them is not critical.
|
||||
*/
|
||||
public function __construct( $field_type_slug, $args ) {
|
||||
|
||||
if( sanitize_title( $field_type_slug ) != $field_type_slug ) {
|
||||
throw new InvalidArgumentException( 'Invalid field type slug.' );
|
||||
}
|
||||
|
||||
if( ! is_array( $args ) ) {
|
||||
throw new InvalidArgumentException( 'Wrong arguments provided.' );
|
||||
}
|
||||
|
||||
$this->field_type_slug = $field_type_slug;
|
||||
|
||||
// Try to fall back to legacy "title", and if even that fails, use id instead.
|
||||
$this->display_name = sanitize_text_field( wpcf_getarr( $args, 'display_name', wpcf_getarr( $args, 'title', $field_type_slug ) ) );
|
||||
|
||||
$this->description = wpcf_getarr( $args, 'description', '' );
|
||||
$this->args = $args;
|
||||
}
|
||||
|
||||
|
||||
public function get_slug() { return $this->field_type_slug; }
|
||||
|
||||
public function get_display_name() { return $this->display_name; }
|
||||
|
||||
public function get_description() { return $this->description; }
|
||||
|
||||
|
||||
/**
|
||||
* Determine if the fields of this type can be repetitive.
|
||||
*
|
||||
* @return bool
|
||||
* @since 2.0
|
||||
*/
|
||||
public function can_be_repetitive() { return true; }
|
||||
|
||||
|
||||
/**
|
||||
* Direct access to the field type configuration.
|
||||
*
|
||||
* It is strongly encouraged to write custom (and safe) getters for anything you need to get from it.
|
||||
*
|
||||
* @param null|string $argument_name Specific argument name or null to return all arguments.
|
||||
* @param string $default Default value when a specific argument is not set.
|
||||
* @return array|mixed
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_args( $argument_name = null, $default = '' ) {
|
||||
if( null == $argument_name ) {
|
||||
return $this->args;
|
||||
} else {
|
||||
return wpcf_getarr( $this->args, $argument_name, $default );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve CSS classes for a field type icon.
|
||||
*
|
||||
* To be placed in the i tag.
|
||||
*
|
||||
* @return string One or more CSS classes separated by spaces.
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_icon_classes() {
|
||||
$fa_class = $this->get_args( 'font-awesome', null );
|
||||
if( null != $fa_class ) {
|
||||
return sprintf( 'fa fa-%s', esc_attr( $fa_class ) );
|
||||
}
|
||||
|
||||
$types_class = $this->get_args( 'types-field-image', null );
|
||||
if( null != $types_class ) {
|
||||
return sprintf( 'types-field-icon types-field-icon-%s', esc_attr( $types_class ) );
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform field type-specific sanitization of the field definition array.
|
||||
*
|
||||
* @link https://git.onthegosystems.com/toolset/types/wikis/database-layer/field-definition-arrays
|
||||
* @param $definition_array
|
||||
* @return array Sanitized definition array
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function sanitize_field_definition_array_type_specific( $definition_array ) {
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform a very generic sanitization of the field definition array.
|
||||
*
|
||||
* Should be used only by sanitize_field_definition_array().
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
private function sanitize_field_definition_array_generic( $definition_array ) {
|
||||
// slug: sanitize_title
|
||||
$definition_array['slug'] = sanitize_title( wpcf_getarr( $definition_array, 'slug' ) );
|
||||
|
||||
// type: default to textfield
|
||||
$definition_array['type'] = wpcf_getarr( $definition_array, 'type', Types_Field_Type_Definition_Factory::TEXTFIELD );
|
||||
|
||||
// name: sanitize_text_field
|
||||
$definition_array['name'] = sanitize_text_field( wpcf_getarr( $definition_array, 'name' ) );
|
||||
|
||||
// description: ensure it is set
|
||||
$definition_array['description'] = wpcf_getarr( $definition_array, 'description' );
|
||||
|
||||
// meta_key: default to wpcf-{$slug}
|
||||
$definition_array['meta_key'] = wpcf_getarr( $definition_array, 'meta_key', WPCF_Field_Definition::FIELD_META_KEY_PREFIX . $definition_array['slug'] );
|
||||
|
||||
// data: must be an array
|
||||
$definition_array['data'] = wpcf_ensarr( wpcf_getarr( $definition_array, 'data' ) );
|
||||
|
||||
// data[conditional_display]: must be an array
|
||||
$definition_array['data']['conditional_display'] = wpcf_ensarr( wpcf_getarr( $definition_array['data'], 'conditional_display' ) );
|
||||
|
||||
// data[validate]: must be an array
|
||||
$definition_array['data']['validate'] = wpcf_ensarr( wpcf_getarr( $definition_array['data'], 'validate' ) );
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure that the field definition array contains all necessary information.
|
||||
*
|
||||
* Note: This is a WIP, currently it sanitizes only very specific cases. It should be extended in the future.
|
||||
*
|
||||
* @link https://git.onthegosystems.com/toolset/types/wikis/database-layer/field-definition-arrays
|
||||
* @param array $definition_array Field definition array
|
||||
* @return array Field definition array that is safe to be used even with legacy code.
|
||||
* @since 2.0
|
||||
*/
|
||||
public final function sanitize_field_definition_array( $definition_array ) {
|
||||
|
||||
/**
|
||||
* types_pre_sanitize_field_definition_array
|
||||
*
|
||||
* Allow for additional field definition array sanitization before the standard one runs.
|
||||
*
|
||||
* @param mixed $definition_array
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
$definition_array = wpcf_ensarr( apply_filters( 'types_pre_sanitize_field_definition_array', $definition_array ) );
|
||||
|
||||
$definition_array = $this->sanitize_field_definition_array_generic( $definition_array );
|
||||
|
||||
$definition_array = $this->sanitize_numeric_validation( $definition_array );
|
||||
|
||||
$definition_array = $this->sanitize_field_definition_array_type_specific( $definition_array );
|
||||
|
||||
/**
|
||||
* types_post_sanitize_field_definition_array
|
||||
*
|
||||
* Allow for additional field definition array sanitization after the standard one runs.
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.1
|
||||
*/
|
||||
$definition_array = wpcf_ensarr( apply_filters( 'types_post_sanitize_field_definition_array', $definition_array ) );
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For all fields, remove the "number" validation option.
|
||||
*
|
||||
* Numeric field will override this and do the opposite instead.
|
||||
*
|
||||
* @param array $definition_array
|
||||
* @return array
|
||||
* @since 2.0
|
||||
*/
|
||||
protected function sanitize_numeric_validation( $definition_array ) {
|
||||
|
||||
// This is what wpcf_admin_custom_fields_change_type() was doing.
|
||||
if( isset( $definition_array['data']['validate']['number'] ) ) {
|
||||
unset( $definition_array['data']['validate']['number'] );
|
||||
}
|
||||
|
||||
return $definition_array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform a basic "isset" sanitization of an array element.
|
||||
*
|
||||
* @param array $source
|
||||
* @param string $element_name Name of the element to sanitize.
|
||||
* @param string $default Default value for the element if not set or invalid.
|
||||
* @param null|array $allowed If an array, defines the set of allowed values for the element.
|
||||
* @param null|string $nested_key If not null, the element will be taken from $source[$nested_key][$element_name].
|
||||
* @return array Updated source array.
|
||||
* @since 2.1
|
||||
*/
|
||||
protected function sanitize_element_isset( $source, $element_name, $default = '', $allowed = null, $nested_key = null ) {
|
||||
$src_array = ( null == $nested_key ? $source : $source[ $nested_key ] );
|
||||
$value = wpcf_getarr( $src_array, $element_name, $default, $allowed );
|
||||
|
||||
if( null == $nested_key ) {
|
||||
$source[ $element_name ] = $value;
|
||||
} else {
|
||||
$source[ $nested_key ][ $element_name ] = $value;
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Factory class for loading field type definitions.
|
||||
*
|
||||
* Handles creation of the objects as well as their caching.
|
||||
*
|
||||
* Currently it is only possible to load existing field types, not create new ones. We're depending on the legacy code
|
||||
* in WPCF_Fields and field types defined through specially named functions. But that is hidden from anyone who uses
|
||||
* this class.
|
||||
*
|
||||
* @since 1.9
|
||||
*/
|
||||
class Types_Field_Type_Definition_Factory {
|
||||
|
||||
const AUDIO = 'audio';
|
||||
const COLORPICKER = 'colorpicker';
|
||||
const DATE = 'date';
|
||||
const EMBED = 'embed';
|
||||
const FILE = 'file';
|
||||
const GOOGLE_ADDRESS = 'google_address';
|
||||
const CHECKBOX = 'checkbox';
|
||||
const CHECKBOXES = 'checkboxes';
|
||||
const IMAGE = 'image';
|
||||
const NUMERIC = 'numeric';
|
||||
const RADIO = 'radio';
|
||||
const SELECT = 'select';
|
||||
const SKYPE = 'skype';
|
||||
const TEXTAREA = 'textarea';
|
||||
const TEXTFIELD = 'textfield';
|
||||
const URL = 'url';
|
||||
const VIDEO = 'video';
|
||||
const WYSIWYG = 'wysiwyg';
|
||||
|
||||
private static $instance = null;
|
||||
|
||||
private function __construct() { }
|
||||
|
||||
private function __clone() { }
|
||||
|
||||
|
||||
public static function get_instance() {
|
||||
if( null == self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @var array Associative array of instantiated field type definitions, indexed by field type slugs ("checkbox",
|
||||
* "email" and such).
|
||||
*/
|
||||
private $field_type_definitions = array();
|
||||
|
||||
|
||||
/**
|
||||
* @var null|array Cached array containing path to files (!) that contain specially named functions (!) that
|
||||
* can be used to return configuration array for a field type (!). We're caching it because
|
||||
* WPCF_Fields::getFieldsTypes() applies a filter each time it is called.
|
||||
*/
|
||||
private $legacy_field_types = null;
|
||||
|
||||
|
||||
/**
|
||||
* @return array See $legacy_field_types.
|
||||
*/
|
||||
private function get_legacy_field_types() {
|
||||
if( null == $this->legacy_field_types ) {
|
||||
$this->legacy_field_types = WPCF_Fields::getFieldsTypes();
|
||||
}
|
||||
return $this->legacy_field_types;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a field type definition.
|
||||
*
|
||||
* @param string $field_type_slug Slug of the field type. If the function fails to find the field type and the slug
|
||||
* starts with a "wpcf-" prefix, it attempts to remove it and search again. This way, passing a field type ID,
|
||||
* which usually has this form, is also supported.
|
||||
* @return null|Types_Field_Type_Definition Field type definition or null if it can't be loaded.
|
||||
*/
|
||||
public function load_field_type_definition( $field_type_slug ) {
|
||||
|
||||
if( !is_string( $field_type_slug ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if we can use cached version.
|
||||
if( !array_key_exists( $field_type_slug, $this->field_type_definitions ) ) {
|
||||
|
||||
// now it gets hacky
|
||||
$field_types = $this->get_legacy_field_types();
|
||||
if( !array_key_exists( $field_type_slug, $field_types ) ) {
|
||||
// Field slug not recognized. Maybe we got a field identifier instead. Check if we can remove
|
||||
// the wpcf- prefix and try again.
|
||||
$prefix = 'wpcf-';
|
||||
if( substr( $field_type_slug, 0, strlen( $prefix ) ) == $prefix ) {
|
||||
$field_type_slug = substr( $field_type_slug, strlen( $prefix ) );
|
||||
if( !array_key_exists( $field_type_slug, $field_types ) ) {
|
||||
// Removing prefix didn't help
|
||||
return null;
|
||||
}
|
||||
// Check the cache again (now with correct slug).
|
||||
if( array_key_exists( $field_type_slug, $this->field_type_definitions ) ) {
|
||||
return $this->field_type_definitions[ $field_type_slug ];
|
||||
}
|
||||
} else {
|
||||
// There was no prefix to remove.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Not using getFieldTypeData() directly to avoid unnecessary getFieldsTypes() and filter applying.
|
||||
$field_type_configuration_path = $field_types[ $field_type_slug ];
|
||||
$field_type_configuration = WPCF_Fields::getFieldTypeConfig( $field_type_configuration_path );
|
||||
|
||||
$field_type_id = wpcf_getarr( $field_type_configuration, 'id', null );
|
||||
if( null == $field_type_id ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$field_type_definition = $this->create_definition_instance( $field_type_slug, $field_type_configuration );
|
||||
} catch( Exception $e ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Save new instance to cache.
|
||||
$this->field_type_definitions[ $field_type_slug ] = $field_type_definition;
|
||||
}
|
||||
|
||||
// Use cache.
|
||||
return $this->field_type_definitions[ $field_type_slug ];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the proper instance of a type definition class, based on the type slug.
|
||||
*
|
||||
* @param string $field_type_slug
|
||||
* @param array $field_type_configuration Legacy configuration array
|
||||
* @return Types_Field_Type_Definition
|
||||
* @since 2.0
|
||||
* @throws Exception
|
||||
*/
|
||||
private function create_definition_instance( $field_type_slug, $field_type_configuration ) {
|
||||
switch( $field_type_slug ) {
|
||||
case self::DATE:
|
||||
return new Types_Field_Type_Definition_Date( $field_type_configuration );
|
||||
case self::CHECKBOX:
|
||||
return new Types_Field_Type_Definition_Checkbox( $field_type_configuration );
|
||||
case self::CHECKBOXES:
|
||||
return new Types_Field_Type_Definition_Checkboxes( $field_type_configuration );
|
||||
case self::NUMERIC:
|
||||
return new Types_Field_Type_Definition_Numeric( $field_type_configuration );
|
||||
case self::RADIO:
|
||||
return new Types_Field_Type_Definition_Radio( $field_type_configuration );
|
||||
case self::SELECT:
|
||||
return new Types_Field_Type_Definition_Select( $field_type_configuration );
|
||||
case self::WYSIWYG:
|
||||
return new Types_Field_Type_Definition_Singular( $field_type_slug, $field_type_configuration );
|
||||
default:
|
||||
return new Types_Field_Type_Definition( $field_type_slug, $field_type_configuration );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get field type definitions from an array of slugs.
|
||||
*
|
||||
* If a definition cannot be loaded for a given slug, the slug is skipped without reporting an error in any other way.
|
||||
*
|
||||
* @param string[] $field_type_slugs
|
||||
* @return Types_Field_Type_Definition[]
|
||||
* @since 2.0
|
||||
*/
|
||||
public function load_multiple_definitions( $field_type_slugs ) {
|
||||
$results = array();
|
||||
$field_type_slugs = wpcf_ensarr( $field_type_slugs );
|
||||
foreach( $field_type_slugs as $field_type_slug ) {
|
||||
$type_definition = $this->load_field_type_definition( $field_type_slug );
|
||||
if( null != $type_definition ) {
|
||||
$results[ $field_type_slug ] = $type_definition;
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all field type definitions available.
|
||||
*
|
||||
* @return Types_Field_Type_Definition[]
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_all_definitions() {
|
||||
$legacy_types = $this->get_legacy_field_types();
|
||||
$definitions = array();
|
||||
foreach( $legacy_types as $type_slug => $ignored ) {
|
||||
$defintion = $this->load_field_type_definition( $type_slug );
|
||||
if( null != $defintion ) {
|
||||
$definitions[] = $defintion;
|
||||
}
|
||||
}
|
||||
return $definitions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a map of all field definition slugs to their properties.
|
||||
*
|
||||
* @return string[]
|
||||
* @since 2.0
|
||||
*/
|
||||
public function get_field_type_definitions() {
|
||||
$field_types = $this->get_all_definitions();
|
||||
$field_type_names = array();
|
||||
foreach( $field_types as $field_type ) {
|
||||
$field_type_names[ $field_type->get_slug() ] = array(
|
||||
'slug' => $field_type->get_slug(),
|
||||
'displayName' => stripslashes( $field_type->get_display_name() ),
|
||||
'canBeRepetitive' => $field_type->can_be_repetitive(),
|
||||
'iconClasses' => $field_type->get_icon_classes()
|
||||
);
|
||||
}
|
||||
|
||||
return $field_type_names;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static shortcut to load_field_type_definition.
|
||||
*
|
||||
* @param string $field_type_slug
|
||||
* @return null|Types_Field_Type_Definition
|
||||
*/
|
||||
public static function load( $field_type_slug ) {
|
||||
// we cannot use self::get_instance here, because of low PHP requirements and missing get_called_class function
|
||||
// we have a fallback class for get_called_class but that scans files by debug_backtrace and return 'self'
|
||||
// instead of Types_Field_Type_Definition_Factory like the original get_called_class() function does
|
||||
// ends in an error because of parents (abstract) $var = new self();
|
||||
return Types_Field_Type_Definition_Factory::get_instance()->load_field_type_definition( $field_type_slug );
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition
|
||||
*
|
||||
* FIXME please document this!
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class Types_Helper_Condition {
|
||||
|
||||
public static $post_type;
|
||||
|
||||
protected $condition;
|
||||
|
||||
protected static function get_type_name() {
|
||||
// per post
|
||||
if( isset( $_GET['post'] ) ) {
|
||||
$get_type_name_id = (int) $_GET['post'];
|
||||
return get_post_type( $get_type_name_id );
|
||||
}
|
||||
|
||||
return self::$post_type->name;
|
||||
}
|
||||
|
||||
public function set_condition( $value ) {
|
||||
$this->condition = $value;
|
||||
}
|
||||
|
||||
public function valid() {}
|
||||
|
||||
public static function set_post_type( $posttype = false ) {
|
||||
if( ! $posttype ) {
|
||||
global $typenow;
|
||||
|
||||
$posttype = isset( $typenow ) && ! empty( $typenow ) ? $typenow : false;
|
||||
}
|
||||
|
||||
if( $posttype )
|
||||
self::$post_type = get_post_type_object( $posttype );
|
||||
}
|
||||
|
||||
public static function get_post_type() {
|
||||
if( self::$post_type === null )
|
||||
self::set_post_type();
|
||||
|
||||
return self::$post_type;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Archive_Exists
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Archive_Exists extends Types_Helper_Condition_Template {
|
||||
|
||||
public function __construct() {
|
||||
$cpt = Types_Helper_Condition::get_post_type();
|
||||
|
||||
$this->templates = array(
|
||||
'archive-' . $cpt->name . '.php',
|
||||
'archive.php'
|
||||
);
|
||||
}
|
||||
|
||||
protected function has_archive() {
|
||||
$cpt = Types_Helper_Condition::get_post_type();
|
||||
if( ! get_post_type_archive_link( $cpt->name ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function valid() {
|
||||
if( ! $this->has_archive() )
|
||||
return false;
|
||||
|
||||
return parent::valid();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Archive_Has_Fields
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Archive_Has_Fields extends Types_Helper_Condition_Archive_No_Fields {
|
||||
|
||||
public function valid() {
|
||||
if( ! $this->has_archive() )
|
||||
return false;
|
||||
|
||||
$template = $this->find_template();
|
||||
|
||||
// no template available
|
||||
if( empty( $template ) )
|
||||
return false;
|
||||
|
||||
// opposite of parents "No Fields".
|
||||
return ! parent::valid();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Archive_Missing
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Archive_Missing extends Types_Helper_Condition_Archive_Exists {
|
||||
// this is valid if no template is found
|
||||
public function valid() {
|
||||
if( ! $this->has_archive() )
|
||||
return false;
|
||||
|
||||
// opposite of parents "Archive Exists"
|
||||
return ! parent::valid();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Archive_No_Fields
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Archive_No_Fields extends Types_Helper_Condition_Archive_Missing {
|
||||
|
||||
public function valid() {
|
||||
if( ! $this->has_archive() )
|
||||
return false;
|
||||
|
||||
$template = $this->find_template();
|
||||
|
||||
// no template available
|
||||
if( empty( $template ) )
|
||||
return false;
|
||||
|
||||
// do not check if there are no fields assigned to current post
|
||||
// this check is not placed very well as it's out of class scope
|
||||
$check_fields_assigned = new Types_Helper_Condition_Type_Fields_Assigned();
|
||||
if( ! $check_fields_assigned->valid() )
|
||||
return false;
|
||||
|
||||
$file = new Toolset_Filesystem_File();
|
||||
|
||||
// abort if file can't be found
|
||||
if( ! $file->open( $template ) )
|
||||
return false;
|
||||
|
||||
// check for fields, abort if there results in true
|
||||
if( $file->search( array( 'types_render_field', 'wpcf-' ) ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Archive_No_Support
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Archive_No_Support extends Types_Helper_Condition_Archive_Support {
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function valid() {
|
||||
return ! parent::valid();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Archive_Support
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Archive_Support extends Types_Helper_Condition {
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function valid() {
|
||||
$cpt = Types_Helper_Condition::get_post_type();
|
||||
|
||||
if ( ! $cpt->has_archive && $cpt->name != 'post' )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Cred_Active
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Cred_Active extends Types_Helper_Condition {
|
||||
|
||||
public function valid() {
|
||||
if( defined( 'CRED_FE_VERSION' ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Cred_Forms_Exist
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Cred_Forms_Exist extends Types_Helper_Condition_Cred_Active {
|
||||
|
||||
public static $forms_per_post_type;
|
||||
|
||||
public function valid() {
|
||||
// false if cred not active
|
||||
if( ! parent::valid() )
|
||||
return false;
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$cpt = Types_Helper_Condition::get_post_type();
|
||||
|
||||
if( isset( self::$forms_per_post_type[$cpt->name] ) )
|
||||
return true;
|
||||
|
||||
// @todo check with Francesco if CRED has a get_forms_of_post_type() function
|
||||
$forms_settings = $wpdb->get_results( "SELECT meta_value, post_id FROM $wpdb->postmeta WHERE meta_key = '_cred_form_settings'" );
|
||||
|
||||
foreach( $forms_settings as $setting ) {
|
||||
$post_type = false;
|
||||
$setting->meta_value = unserialize( $setting->meta_value );
|
||||
|
||||
// post type
|
||||
if( isset( $setting->meta_value->post['post_type'] ) )
|
||||
$post_type = $setting->meta_value->post['post_type'];
|
||||
|
||||
// different structure created by CredFormCreator
|
||||
// (surely old style, but compatible with new and restructured after first form save)
|
||||
if( ! $post_type && is_array( $setting->meta_value ) && isset( $setting->meta_value['post_type'] ) )
|
||||
$post_type = $setting->meta_value['post_type'];
|
||||
|
||||
// another structure...
|
||||
if( ! $post_type && is_object( $setting->meta_value ) && isset( $setting->meta_value->post_type ) )
|
||||
$post_type = $setting->meta_value->post_type;
|
||||
|
||||
if( $post_type && $cpt->name == $post_type ) {
|
||||
$title = get_the_title( $setting->post_id );
|
||||
|
||||
self::$forms_per_post_type[$cpt->name][] = array(
|
||||
'id' => $setting->post_id,
|
||||
'name' => $title
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if( isset( self::$forms_per_post_type[$cpt->name] ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get_forms_of_post_type() {
|
||||
$cpt = Types_Helper_Condition::get_post_type();
|
||||
|
||||
if( isset( self::$forms_per_post_type[$cpt->name] ) )
|
||||
return self::$forms_per_post_type[$cpt->name];
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Cred_Forms_Missing
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Cred_Forms_Missing extends Types_Helper_Condition_Cred_Forms_Exist {
|
||||
|
||||
public function valid() {
|
||||
// if views not active
|
||||
if( ! defined( 'CRED_FE_VERSION' ) )
|
||||
return false;
|
||||
|
||||
// opposite of parent "forms exists"
|
||||
return ! parent::valid();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Cred_Missing
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Cred_Missing extends Types_Helper_Condition_Cred_Active {
|
||||
|
||||
public function valid() {
|
||||
return ! parent::valid();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Layouts_Active
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Layouts_Active extends Types_Helper_Condition {
|
||||
|
||||
public function valid() {
|
||||
if( defined( 'WPDDL_DEVELOPMENT' ) || defined( 'WPDDL_PRODUCTION' ) )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Layouts_Archive_Exists
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Layouts_Archive_Exists extends Types_Helper_Condition_Template {
|
||||
|
||||
private static $layout_id = array();
|
||||
private static $layout_name = array();
|
||||
|
||||
public function valid() {
|
||||
if( ! defined( 'WPDDL_DEVELOPMENT' ) && ! defined( 'WPDDL_PRODUCTION' ) )
|
||||
return false;
|
||||
|
||||
$type = self::get_type_name();
|
||||
|
||||
$layouts = get_option( WPDDL_GENERAL_OPTIONS, array() );
|
||||
|
||||
// for type 'post'
|
||||
if( $type == 'post' ) {
|
||||
self::$layout_id[$type] = array_key_exists( 'layouts_home-blog-page', $layouts )
|
||||
? $layouts['layouts_home-blog-page']
|
||||
: false;
|
||||
|
||||
return self::$layout_id[$type];
|
||||
}
|
||||
|
||||
// all cpts
|
||||
self::$layout_id[$type] = array_key_exists( 'layouts_cpt_' . $type, $layouts )
|
||||
? self::$layout_id[$type] = $layouts['layouts_cpt_' . $type]
|
||||
: false;
|
||||
|
||||
return self::$layout_id[$type];
|
||||
}
|
||||
|
||||
public static function get_layout_id() {
|
||||
$type = self::get_type_name();
|
||||
|
||||
if( ! isset( self::$layout_id[$type] ) ) {
|
||||
$self = new Types_Helper_Condition_Layouts_Archive_Exists();
|
||||
$self->valid();
|
||||
}
|
||||
|
||||
return self::$layout_id[$type];
|
||||
}
|
||||
|
||||
public static function get_layout_name() {
|
||||
$type = self::get_type_name();
|
||||
|
||||
if( !isset( self::$layout_name[$type] ) )
|
||||
self::$layout_name[$type] = get_the_title( self::get_layout_id() );
|
||||
|
||||
return self::$layout_name[$type];
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Layouts_Archive_Missing
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Layouts_Archive_Missing extends Types_Helper_Condition_Layouts_Archive_Exists {
|
||||
|
||||
public function valid() {
|
||||
if( ! defined( 'WPDDL_GENERAL_OPTIONS' ) )
|
||||
return false;
|
||||
|
||||
// opposite of parents "exists"
|
||||
return ! parent::valid();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Layouts_Compatible
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Layouts_Compatible extends Types_Helper_Condition_Template {
|
||||
|
||||
public function __construct() {
|
||||
$cpt = Types_Helper_Condition::get_post_type();
|
||||
|
||||
$this->templates = array(
|
||||
'single-' . $cpt->name . '.php',
|
||||
'archive-' . $cpt->name . '.php',
|
||||
'single.php',
|
||||
'archive.php',
|
||||
'index.php'
|
||||
);
|
||||
}
|
||||
|
||||
public function valid() {
|
||||
// theme + theme integration running
|
||||
if ( defined( 'LAYOUTS_INTEGRATION_THEME_NAME' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$filesystem = new Toolset_Filesystem_File();
|
||||
foreach ( $this->templates as $name => $file ) {
|
||||
// file exists
|
||||
if ( $filesystem->open( get_template_directory() . '/' . $file )
|
||||
|| $filesystem->open( get_stylesheet_directory() . '/' . $file )
|
||||
) {
|
||||
// supports layouts
|
||||
if ( $filesystem->search( 'the_ddlayout' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if for example single.php exists and it does not support Layouts we don't need to look at index.php
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// no file exists
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Layouts_Missing
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Layouts_Missing extends Types_Helper_Condition_Layouts_Active {
|
||||
|
||||
public function valid() {
|
||||
return ! parent::valid();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Layouts_Template_Exists
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Layouts_Template_Exists extends Types_Helper_Condition_Template {
|
||||
|
||||
public static $layout_id = array();
|
||||
public static $layout_name = array();
|
||||
|
||||
public function valid() {
|
||||
if( ! defined( 'WPDDL_DEVELOPMENT' ) && ! defined( 'WPDDL_PRODUCTION' ) )
|
||||
return false;
|
||||
|
||||
$type = self::get_type_name();
|
||||
|
||||
if( isset( self::$layout_id[$type] ) && self::$layout_id[$type] !== null && self::$layout_id[$type] !== false )
|
||||
return true;
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$layouts_per_post_type = $wpdb->get_results( "SELECT meta_value, post_id FROM $wpdb->postmeta WHERE meta_key = '_ddl_post_types_was_batched'" );
|
||||
|
||||
foreach( $layouts_per_post_type as $setting ) {
|
||||
|
||||
$setting->meta_value = unserialize( $setting->meta_value );
|
||||
|
||||
if( is_array( $setting->meta_value )
|
||||
&& in_array( $type, $setting->meta_value ) ) {
|
||||
|
||||
if( get_post_status( $setting->post_id) == 'trash' )
|
||||
continue;
|
||||
|
||||
$title = get_the_title( $setting->post_id );
|
||||
self::$layout_id[$type] = $setting->post_id;
|
||||
self::$layout_name[$type] = $title;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
self::$layout_id[$type] = false;
|
||||
self::$layout_name[$type] = false;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public static function get_layout_id() {
|
||||
$type = self::get_type_name();
|
||||
|
||||
if( ! isset( self::$layout_id[$type] ) ) {
|
||||
$self = new Types_Helper_Condition_Layouts_Template_Exists();
|
||||
$self->valid();
|
||||
}
|
||||
|
||||
return self::$layout_id[$type];
|
||||
}
|
||||
|
||||
public static function get_layout_name() {
|
||||
$type = self::get_type_name();
|
||||
|
||||
if( ! isset( self::$layout_name[$type] ) )
|
||||
self::$layout_name[$type] = get_the_title( self::get_layout_id() );
|
||||
|
||||
return self::$layout_name[$type];
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Layouts_Template_Missing
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Layouts_Template_Missing extends Types_Helper_Condition_Layouts_Template_Exists {
|
||||
|
||||
public function valid() {
|
||||
$type = self::get_type_name();
|
||||
if( isset( parent::$layout_id[$type] )
|
||||
&& parent::$layout_id[$type] !== null
|
||||
&& parent::$layout_id[$type] !== false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return ! parent::valid();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Screen
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Screen extends Types_Helper_Condition {
|
||||
|
||||
// check if current screen is screen
|
||||
public function valid() {
|
||||
global $pagenow;
|
||||
|
||||
if( empty( $pagenow ) )
|
||||
return false;
|
||||
|
||||
if( $this->condition == $pagenow )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Single_Exists
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Single_Exists extends Types_Helper_Condition_Template {
|
||||
|
||||
public function __construct() {
|
||||
$cpt = Types_Helper_Condition::get_post_type();
|
||||
|
||||
$this->templates = array(
|
||||
'single-' . $cpt->name . '.php',
|
||||
'single.php'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Single_Has_Fields
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Single_Has_Fields extends Types_Helper_Condition_Single_No_Fields {
|
||||
|
||||
public function valid() {
|
||||
|
||||
$template = $this->find_template();
|
||||
|
||||
// no template available
|
||||
if( empty( $template ) )
|
||||
return false;
|
||||
|
||||
// opposite of parents "No Fields".
|
||||
return ! parent::valid();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Single_Missing
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Single_Missing extends Types_Helper_Condition_Single_Exists {
|
||||
// this is valid if no template is found
|
||||
public function valid() {
|
||||
// opposite of parents "Single Exists"
|
||||
return ! parent::valid();
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Single_No_Fields
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class Types_Helper_Condition_Single_No_Fields extends Types_Helper_Condition_Single_Missing {
|
||||
|
||||
public function valid() {
|
||||
$template = $this->find_template();
|
||||
|
||||
// no template available
|
||||
if( empty( $template ) )
|
||||
return false;
|
||||
|
||||
// do not check if there are no fields assigned to current post
|
||||
// this check is not placed very well as it's out of class scope
|
||||
$check_fields_assigned = new Types_Helper_Condition_Type_Fields_Assigned();
|
||||
if( ! $check_fields_assigned->valid() )
|
||||
return false;
|
||||
|
||||
$file = new Toolset_Filesystem_File();
|
||||
|
||||
// abort if file can't be found
|
||||
if( ! $file->open( $template ) )
|
||||
return false;
|
||||
|
||||
// check for fields, abort if there results in true
|
||||
if( $file->search( array( 'types_render_field', 'wpcf-' ) ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Types_Helper_Condition_Template
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
abstract class Types_Helper_Condition_Template extends Types_Helper_Condition {
|
||||
|
||||
protected $templates;
|
||||
|
||||
public function find_template() {
|
||||
$template = locate_template( $this->templates ) ;
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
// check if current screen is screen
|
||||
public function valid() {
|
||||
$template = $this->find_template();
|
||||
|
||||
if( empty( $template ) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Types_Helper_Condition_Type_Fields_Assigned extends Types_Helper_Condition {
|
||||
|
||||
public function valid() {
|
||||
$post_type = Types_Helper_Condition::get_post_type();
|
||||
|
||||
// false if we have no post type
|
||||
if( ! isset( $post_type->name ) )
|
||||
return false;
|
||||
|
||||
// query a post
|
||||
$query = new WP_Query( 'post_type=' . $post_type->name . '&posts_per_page=1' );
|
||||
|
||||
if( $query->have_posts() ) {
|
||||
$post = $query->posts[0];
|
||||
|
||||
// for the case no post created yet (post fields group edit page / post type edit page)
|
||||
} else {
|
||||
$post = new stdClass();
|
||||
$post->ID = -1;
|
||||
$post->post_type = $post_type->name;
|
||||
}
|
||||
|
||||
if( !function_exists( 'wpcf_admin_post_get_post_groups_fields') )
|
||||
include_once( WPCF_EMBEDDED_ABSPATH . '/includes/fields-post.php' );
|
||||
|
||||
$fields = wpcf_admin_post_get_post_groups_fields( $post );
|
||||
|
||||
if(
|
||||
isset( $fields )
|
||||
&& is_array( $fields )
|
||||
&& !empty( $fields )
|
||||
) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Types_Helper_Condition_Type_No_Post_Or_Page extends Types_Helper_Condition_Type_Post_Or_Page {
|
||||
|
||||
public function valid() {
|
||||
return ! parent::valid();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user