misleading version information
-
Plugin is said to be 1.0.0 (= first stable release).
But IMHO it’s nowhere near stable, if even finished. I understand it may be a “best effort” work, but numbering 0.2 may better represent the usability state.
Although please let me comment that there is a *bunch* of unused code, complicated construct, and convoluted stuff like “custom loader”.
I had to remove almost 500 loc in order to simply not bug me, but that was not enough really give me incentive to reshape it further.Patch below
8 files changed, 48 insertions(+), 566 deletions(-)diff --git a/acf-form-builder.php b/acf-form-builder.php index d06592f..0360232 100644 --- a/acf-form-builder.php +++ b/acf-form-builder.php @@ -18,51 +18,47 @@ die; } -/** - * The code that runs during plugin activation. - * This action is documented in includes/class-acf-form-builder-activator.php - */ -function activate_acf_form_builder() { - require_once plugin_dir_path( __FILE__ ) . 'includes/class-acf-form-builder-activator.php'; - Acf_Form_Builder_Activator::activate(); -} +class Acf_Form_Builder { -/** - * The code that runs during plugin deactivation. - * This action is documented in includes/class-acf-form-builder-deactivator.php - */ -function deactivate_acf_form_builder() { - require_once plugin_dir_path( __FILE__ ) . 'includes/class-acf-form-builder-deactivator.php'; - Acf_Form_Builder_Deactivator::deactivate(); -} + const acf_form_builder = 'acf-form-buider'; + const version = "1.0.0"; -register_activation_hook( __FILE__, 'activate_acf_form_builder' ); -register_deactivation_hook( __FILE__, 'deactivate_acf_form_builder' ); + public function __construct() { + // add field in to acf field admin + $dir = plugin_dir_path( __FILE__ ); -/** - * The core plugin class that is used to define internationalization, - * admin-specific hooks, and public-facing site hooks. - */ -require plugin_dir_path( __FILE__ ) . 'includes/class-acf-form-builder.php'; + include_once( $dir . 'includes/settings/class-acf-form-builder-settings.php' ); + // once all plugins are loaded, figure out if we need to stub any functions + add_action('acf/render_field_settings','Settings::add_field_display_label_pro'); + add_action('acf/create_field_options', 'Settings::add_field_display_label'); -/** - * Begins execution of the plugin. - * - * Since everything within the plugin is registered via hooks, - * then kicking off the plugin from this point in the file does - * not affect the page life cycle. - * - * @since 1.0.0 - */ -function run_acf_form_builder() { + include_once( $dir . 'includes/default-actions/acf-form-builder-default-actions.php' ); - // add field in to acf field admin - $dir = plugin_dir_path( __FILE__ ); - include_once( $dir . 'includes/settings/class-acf-form-builder-settings.php' ); - include_once( $dir . 'includes/default-actions/acf-form-builder-default-actions.php' ); + add_action( 'plugins_loaded', [__CLASS__, 'load_plugin_textdomain'] ); - $plugin = new Acf_Form_Builder(); - $plugin->run(); + require_once $dir . 'admin/class-acf-form-builder-admin.php'; + $plugin_admin = new Acf_Form_Builder_Admin( self::acf_form_builder, self::version ); + add_action( 'admin_enqueue_scripts', [$plugin_admin, 'enqueue_styles'] ); + add_action( 'admin_enqueue_scripts', [$plugin_admin, 'acf_fb_display_action_fields'] ); + add_action( 'wp_ajax_acf_fb_ajax_change', [$plugin_admin, 'acf_fb_meta_box_ajax_handler'] ); + add_action( 'admin_enqueue_scripts', [$plugin_admin, 'enqueue_scripts'] ); + add_action( 'add_meta_boxes', [$plugin_admin, 'acf_fb_add_custom_box'] ); + add_action( 'save_post', [$plugin_admin, 'acf_fb_save_form_settings_meta'] ); + add_action( 'admin_notices', [$plugin_admin, 'acf_fb_handle_error_before_save'] ); + require_once $dir . 'public/class-acf-form-builder-public.php'; + $plugin_public = new Acf_Form_Builder_Public( self::acf_form_builder, self::version ); + add_action( 'wp_enqueue_scripts', [$plugin_public, 'enqueue_styles'] ); + add_action( 'wp_enqueue_scripts', [$plugin_public, 'enqueue_scripts'] ); + add_action( 'init', [$plugin_public, 'acf_fb_register_shortcode'] ); + add_action( 'template_redirect', [$plugin_public, 'load_acf_form_head'] ); + add_action( 'save_post', [$plugin_admin, 'acf_fb_save_form_settings_meta_fronted'] ); + + } + + public static function load_plugin_textdomain() { + load_plugin_textdomain( self::acf_form_builder, false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' ); + } } -run_acf_form_builder(); \ No newline at end of file + +$plugin = new Acf_Form_Builder(); diff --git a/admin/class-acf-form-builder-admin.php b/admin/class-acf-form-builder-admin.php index b615cc4..c752962 100644 --- a/admin/class-acf-form-builder-admin.php +++ b/admin/class-acf-form-builder-admin.php @@ -168,57 +168,27 @@ public function acf_fb_meta_box_ajax_handler() { public function acf_fb_add_custom_box() { //count forms global $post; - $post_type = $post->post_type; - if ('acf-field-group' == $post_type ) {$post_type = 'acf-field-group';} else {$post_type = 'acf';} - $post_args = array('posts_per_page' => 10, 'post_type' => $post_type, 'exclude' => $post->ID, ); - $other_posts = get_posts($post_args); - foreach ($other_posts as $other_post) { - $get_post_meta = get_post_meta($other_post->ID); - $form_settings = unserialize($get_post_meta['form_settings'][0]); - if (in_array('form', $form_settings)) {$forms_count_result = 2;break;} else {$forms_count_result = 0;} - } - if ($forms_count_result < 1) { - - add_meta_box( - 'acf_fb_form_settings', // Unique ID - 'Form Builder Settings', // Box title - array($this, 'acf_fb_main_custom_box_html'), // Content callback, must be of type callable - array('acf', 'acf-field-group'), // Post type - 'normal', - 'high' - ); - - } else { - - add_meta_box( - 'acf_fb_form_settings', // Unique ID - 'Form Builder Settings', // Box title - array($this, 'acf_fb_custom_error_box_html'), // Content callback, must be of type callable - array('acf', 'acf-field-group'), // Post type - 'normal', - 'high' - ); - } - - } - public function acf_fb_custom_error_box_html() - { - echo '<style>p.acf-cta-action a {color: #fff;font-size: 18px;font-weight: 800;}</style>'; - echo '<p><strong>ACF Form Builder Notice:</strong> You have exceeded the maximum forms that you can use in FREE version. Please update to PRO version to remove the limitations.</p><p style="background: #ff2828;padding: 10px;text-align: center;color: #FFFFFF;"><strong><a style="font-size: 18px;font-weight: 800;color: #fff;" href="https://www.wpwiseguys.com/recommends/acf-form-builder-pro-dashboard/">UPDATE TO PRO VERSION NOW!</a><p></strong>'; + add_meta_box( + 'acf_fb_form_settings', // Unique ID + 'Form Builder Settings', // Box title + array($this, 'acf_fb_main_custom_box_html'), // Content callback, must be of type callable + array('acf', 'acf-field-group'), // Post type + 'normal', + 'high' + ); } public function acf_fb_main_custom_box_html() { global $post; - $post_type = $post->post_type; - $post_meta = get_post_meta($post->ID); if (isset($post_meta['form_settings'])) { $form_settings = unserialize($post_meta['form_settings'][0]); } - ?> + ?> + <style type="text/css"> #acf_fb_form_settings .inside { margin: 0; diff --git a/includes/class-acf-form-builder-activator.php b/includes/class-acf-form-builder-activator.php deleted file mode 100644 index 3d6a16b..0000000 --- a/includes/class-acf-form-builder-activator.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -/** - * Fired during plugin activation - * - * @link https://catsplugins.com - * @since 1.0.0 - * - * @package acf_form_builder - * @subpackage acf_form_builder/includes - */ - -/** - * Fired during plugin activation. - * - * This class defines all code necessary to run during the plugin's activation. - * - * @since 1.0.0 - * @package acf_form_builder - * @subpackage acf_form_builder/includes - * @author Nicholas To <[email protected]> - */ -class Acf_Form_Builder_Activator { - - /** - * Short Description. (use period) - * - * Long Description. - * - * @since 1.0.0 - */ - public static function activate() { - - } - -} diff --git a/includes/class-acf-form-builder-deactivator.php b/includes/class-acf-form-builder-deactivator.php deleted file mode 100644 index 87f78e8..0000000 --- a/includes/class-acf-form-builder-deactivator.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -/** - * Fired during plugin deactivation - * - * @link https://catsplugins.com - * @since 1.0.0 - * - * @package acf_form_builder - * @subpackage acf_form_builder/includes - */ - -/** - * Fired during plugin deactivation. - * - * This class defines all code necessary to run during the plugin's deactivation. - * - * @since 1.0.0 - * @package acf_form_builder - * @subpackage acf_form_builder/includes - * @author Nicholas To <[email protected]> - */ -class Acf_Form_Builder_Deactivator { - - /** - * Short Description. (use period) - * - * Long Description. - * - * @since 1.0.0 - */ - public static function deactivate() { - - } - -} diff --git a/includes/class-acf-form-builder-i18n.php b/includes/class-acf-form-builder-i18n.php deleted file mode 100644 index ecf0ebc..0000000 --- a/includes/class-acf-form-builder-i18n.php +++ /dev/null @@ -1,47 +0,0 @@ -<?php - -/** - * Define the internationalization functionality - * - * Loads and defines the internationalization files for this plugin - * so that it is ready for translation. - * - * @link https://catsplugins.com - * @since 1.0.0 - * - * @package acf_form_builder - * @subpackage acf_form_builder/includes - */ - -/** - * Define the internationalization functionality. - * - * Loads and defines the internationalization files for this plugin - * so that it is ready for translation. - * - * @since 1.0.0 - * @package acf_form_builder - * @subpackage acf_form_builder/includes - * @author Nicholas To <[email protected]> - */ -class Acf_Form_Builder_i18n { - - - /** - * Load the plugin text domain for translation. - * - * @since 1.0.0 - */ - public function load_plugin_textdomain() { - - load_plugin_textdomain( - 'acf-form-buider', - false, - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' - ); - - } - - - -} diff --git a/includes/class-acf-form-builder-loader.php b/includes/class-acf-form-builder-loader.php deleted file mode 100644 index 81bb316..0000000 --- a/includes/class-acf-form-builder-loader.php +++ /dev/null @@ -1,129 +0,0 @@ -<?php - -/** - * Register all actions and filters for the plugin - * - * @link https://catsplugins.com - * @since 1.0.0 - * - * @package acf_form_builder - * @subpackage acf_form_builder/includes - */ - -/** - * Register all actions and filters for the plugin. - * - * Maintain a list of all hooks that are registered throughout - * the plugin, and register them with the WordPress API. Call the - * run function to execute the list of actions and filters. - * - * @package acf_form_builder - * @subpackage acf_form_builder/includes - * @author Nicholas To <[email protected]> - */ -class Acf_Form_Builder_Loader { - - /** - * The array of actions registered with WordPress. - * - * @since 1.0.0 - * @access protected - * @var array $actions The actions registered with WordPress to fire when the plugin loads. - */ - protected $actions; - - /** - * The array of filters registered with WordPress. - * - * @since 1.0.0 - * @access protected - * @var array $filters The filters registered with WordPress to fire when the plugin loads. - */ - protected $filters; - - /** - * Initialize the collections used to maintain the actions and filters. - * - * @since 1.0.0 - */ - public function __construct() { - - $this->actions = array(); - $this->filters = array(); - - } - - /** - * Add a new action to the collection to be registered with WordPress. - * - * @since 1.0.0 - * @param string $hook The name of the WordPress action that is being registered. - * @param object $component A reference to the instance of the object on which the action is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority Optional. he priority at which the function should be fired. Default is 10. - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. - */ - public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { - $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); - } - - /** - * Add a new filter to the collection to be registered with WordPress. - * - * @since 1.0.0 - * @param string $hook The name of the WordPress filter that is being registered. - * @param object $component A reference to the instance of the object on which the filter is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority Optional. he priority at which the function should be fired. Default is 10. - * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 - */ - public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) { - $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); - } - - /** - * A utility function that is used to register the actions and hooks into a single - * collection. - * - * @since 1.0.0 - * @access private - * @param array $hooks The collection of hooks that is being registered (that is, actions or filters). - * @param string $hook The name of the WordPress filter that is being registered. - * @param object $component A reference to the instance of the object on which the filter is defined. - * @param string $callback The name of the function definition on the $component. - * @param int $priority The priority at which the function should be fired. - * @param int $accepted_args The number of arguments that should be passed to the $callback. - * @return array The collection of actions and filters registered with WordPress. - */ - private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) { - - $hooks[] = array( - 'hook' => $hook, - 'component' => $component, - 'callback' => $callback, - 'priority' => $priority, - 'accepted_args' => $accepted_args - ); - - return $hooks; - - } - - /** - * Register the filters and actions with WordPress. - * - * @since 1.0.0 - */ - public function run() { - - foreach ( $this->filters as $hook ) { - add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); - } - - foreach ( $this->actions as $hook ) { - add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] ); - } - - } - -} diff --git a/includes/class-acf-form-builder.php b/includes/class-acf-form-builder.php deleted file mode 100644 index 13f2973..0000000 --- a/includes/class-acf-form-builder.php +++ /dev/null @@ -1,223 +0,0 @@ -<?php - -/** - * The file that defines the core plugin class - * - * A class definition that includes attributes and functions used across both the - * public-facing side of the site and the admin area. - * - * @link https://catsplugins.com - * @since 1.0.0 - * - * @package acf_form_builder - * @subpackage acf_form_builder/includes - */ - -/** - * The core plugin class. - * - * This is used to define internationalization, admin-specific hooks, and - * public-facing site hooks. - * - * Also maintains the unique identifier of this plugin as well as the current - * version of the plugin. - * - * @since 1.0.0 - * @package acf_form_builder - * @subpackage acf_form_builder/includes - * @author Nicholas To <[email protected]> - */ -class Acf_Form_Builder { - - /** - * The loader that's responsible for maintaining and registering all hooks that power - * the plugin. - * - * @since 1.0.0 - * @access protected - * @var Acf_Form_Builder_Loader $loader Maintains and registers all hooks for the plugin. - */ - protected $loader; - - /** - * The unique identifier of this plugin. - * - * @since 1.0.0 - * @access protected - * @var string $acf_form_builder The string used to uniquely identify this plugin. - */ - protected $acf_form_builder; - - /** - * The current version of the plugin. - * - * @since 1.0.0 - * @access protected - * @var string $version The current version of the plugin. - */ - protected $version; - - /** - * Define the core functionality of the plugin. - * - * Set the plugin name and the plugin version that can be used throughout the plugin. - * Load the dependencies, define the locale, and set the hooks for the admin area and - * the public-facing side of the site. - * - * @since 1.0.0 - */ - public function __construct() { - - $this->acf_form_builder = 'acf-form-buider'; - $this->version = '1.0.0'; - - $this->load_dependencies(); - $this->set_locale(); - $this->define_admin_hooks(); - $this->define_public_hooks(); - - } - - /** - * Load the required dependencies for this plugin. - * - * Include the following files that make up the plugin: - * - * - Acf_Form_Builder_Loader. Orchestrates the hooks of the plugin. - * - Acf_Form_Builder_i18n. Defines internationalization functionality. - * - Acf_Form_Builder_Admin. Defines all hooks for the admin area. - * - Acf_Form_Builder_Public. Defines all hooks for the public side of the site. - * - * Create an instance of the loader which will be used to register the hooks - * with WordPress. - * - * @since 1.0.0 - * @access private - */ - private function load_dependencies() { - - /** - * The class responsible for orchestrating the actions and filters of the - * core plugin. - */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-acf-form-builder-loader.php'; - - /** - * The class responsible for defining internationalization functionality - * of the plugin. - */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-acf-form-builder-i18n.php'; - - /** - * The class responsible for defining all actions that occur in the admin area. - */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-acf-form-builder-admin.php'; - - /** - * The class responsible for defining all actions that occur in the public-facing - * side of the site. - */ - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-acf-form-builder-public.php'; - - $this->loader = new Acf_Form_Builder_Loader(); - - } - - /** - * Define the locale for this plugin for internationalization. - * - * Uses the Acf_Form_Builder_i18n class in order to set the domain and to register the hook - * with WordPress. - * - * @since 1.0.0 - * @access private - */ - private function set_locale() { - - $plugin_i18n = new Acf_Form_Builder_i18n(); - - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); - - } - - /** - * Register all of the hooks related to the admin area functionality - * of the plugin. - * - * @since 1.0.0 - * @access private - */ - private function define_admin_hooks() { - - $plugin_admin = new Acf_Form_Builder_Admin( $this->get_acf_form_builder(), $this->get_version() ); - - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'acf_fb_display_action_fields' ); - $this->loader->add_action( 'wp_ajax_acf_fb_ajax_change', $plugin_admin, 'acf_fb_meta_box_ajax_handler' ); - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); - $this->loader->add_action( 'add_meta_boxes', $plugin_admin, 'acf_fb_add_custom_box' ); - $this->loader->add_action( 'save_post', $plugin_admin, 'acf_fb_save_form_settings_meta' ); - $this->loader->add_action( 'admin_notices', $plugin_admin, 'acf_fb_handle_error_before_save' ); - - } - - /** - * Register all of the hooks related to the public-facing functionality - * of the plugin. - * - * @since 1.0.0 - * @access private - */ - private function define_public_hooks() { - - $plugin_public = new Acf_Form_Builder_Public( $this->get_acf_form_builder(), $this->get_version() ); - - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); - $this->loader->add_action( 'init', $plugin_public, 'acf_fb_register_shortcode' ); - $this->loader->add_action( 'template_redirect', $plugin_public, 'load_acf_form_head' ); - $this->loader->add_action( 'save_post', $plugin_admin, 'acf_fb_save_form_settings_meta_fronted' ); - - } - - /** - * Run the loader to execute all of the hooks with WordPress. - * - * @since 1.0.0 - */ - public function run() { - $this->loader->run(); - } - - /** - * The name of the plugin used to uniquely identify it within the context of - * WordPress and to define internationalization functionality. - * - * @since 1.0.0 - * @return string The name of the plugin. - */ - public function get_acf_form_builder() { - return $this->acf_form_builder; - } - - /** - * The reference to the class that orchestrates the hooks with the plugin. - * - * @since 1.0.0 - * @return Acf_Form_Builder_Loader Orchestrates the hooks of the plugin. - */ - public function get_loader() { - return $this->loader; - } - - /** - * Retrieve the version number of the plugin. - * - * @since 1.0.0 - * @return string The version number of the plugin. - */ - public function get_version() { - return $this->version; - } - -} \ No newline at end of file diff --git a/includes/settings/class-acf-form-builder-settings.php b/includes/settings/class-acf-form-builder-settings.php index 48441bd..083781d 100644 --- a/includes/settings/class-acf-form-builder-settings.php +++ b/includes/settings/class-acf-form-builder-settings.php @@ -2,20 +2,8 @@ class Settings { - public function __construct() { - - // once all plugins are loaded, figure out if we need to stub any functions - add_action('plugins_loaded', array($this, 'initialize_functions')); - add_action('acf/render_field_settings', array($this, 'add_field_display_label_pro')); - add_action('acf/create_field_options', array($this, 'add_field_display_label')); - } - - // determind which functions to use, based on what is available - public function initialize_functions() { - } - // NON-PRO ONLY: add a field to the admin interface, that decides whether this field's label gets displayed on the frontend or not - public function add_field_display_label($field) { + public static function add_field_display_label($field) { ?> <tr class="field_display_label"> <td class="label"><label>Form field type</label> @@ -40,7 +28,7 @@ public function add_field_display_label($field) { } // PRO ONLY: add a field to the admin interface, that decides whether this field's label gets displayed on the frontend or not - public function add_field_display_label_pro($field) { + public static function add_field_display_label_pro($field) { // required acf_render_field_wrap(array( 'label' => 'Form field type', @@ -59,4 +47,3 @@ public function add_field_display_label_pro($field) { ), 'tr'); } } -new Settings(); \ No newline at end of file
- The topic ‘misleading version information’ is closed to new replies.