├── templates ├── widget-rss.php ├── widget-meta.php ├── widget-pages.php ├── widget-search.php ├── widget-text.php ├── widget-YOUR-WIDGET.php ├── widget-custom-menu.php ├── widget-tag-cloud.php ├── widget-recent-posts.php ├── widget-recent-comments.php ├── widget-archives.php ├── widget-calendar.php └── widget-categories.php ├── includes ├── lang │ ├── default.mo │ └── default.po ├── views │ ├── support-meta-box.php │ └── how-to-meta-box.php ├── js │ └── acf-widgets.js ├── css │ └── acf-widgets.css ├── acf-404.php ├── ACFW_Widget_Factory.php ├── widgets-setup.php ├── ACFW_Widget.php ├── helper-functions.php ├── default-widgets.php └── admin-setup.php ├── composer.json ├── example-code.php ├── acf-widgets.php ├── readme.md └── EDD_SL_Plugin_Updater.php /templates/widget-rss.php: -------------------------------------------------------------------------------- 1 |

RSS Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /includes/lang/default.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/daronspence/acf-widgets/HEAD/includes/lang/default.mo -------------------------------------------------------------------------------- /templates/widget-meta.php: -------------------------------------------------------------------------------- 1 |

Meta Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-pages.php: -------------------------------------------------------------------------------- 1 |

Pages Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-search.php: -------------------------------------------------------------------------------- 1 |

Search Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-text.php: -------------------------------------------------------------------------------- 1 |

Text Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-YOUR-WIDGET.php: -------------------------------------------------------------------------------- 1 |

Your custom Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-custom-menu.php: -------------------------------------------------------------------------------- 1 |

Custom Menu Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-tag-cloud.php: -------------------------------------------------------------------------------- 1 |

Tag Cloud Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-recent-posts.php: -------------------------------------------------------------------------------- 1 |

Recent Posts Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-recent-comments.php: -------------------------------------------------------------------------------- 1 |

Recent Comments Widget Template. 2 |
3 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-archives.php: -------------------------------------------------------------------------------- 1 | 2 |

Archives Widget Template. 3 |
4 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-calendar.php: -------------------------------------------------------------------------------- 1 | 2 |

Calendar Widget Template. 3 |
4 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /templates/widget-categories.php: -------------------------------------------------------------------------------- 1 | 2 |

Categories Widget Template. 3 |
4 | Provided by the ACF Widgets Plugin.

-------------------------------------------------------------------------------- /includes/views/support-meta-box.php: -------------------------------------------------------------------------------- 1 |

2 |

', ''); ?>

3 |
4 |

5 |

', ''); ?>

-------------------------------------------------------------------------------- /includes/js/acf-widgets.js: -------------------------------------------------------------------------------- 1 | function acfw(){ 2 | var el = jQuery("div[id*='_acf_widget_'] .acf-field"); 3 | var num = 0; 4 | var body = jQuery('body'); 5 | num = el.length; 6 | if ( num > 0 ){ 7 | var remove = el.closest('.widget-content').children('.acfw-no-acf'); 8 | remove.attr('data-display', 'none'); 9 | } 10 | } 11 | function acfw_remove_fields(){ 12 | jQuery('.widget .acf-field').remove(); 13 | } 14 | jQuery(document).ready( acfw ); -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Daronspence/acf-widgets", 3 | "description": "A plugin to easily create widgets for use with ACF and add custom fields to any widget on your site.", 4 | "version": "1.11", 5 | "license": "GPL2+", 6 | "type": "wordpress-plugin", 7 | "keywords": [ 8 | "acf", 9 | "advanced custom fields", 10 | "widgets", 11 | "sidebar" 12 | ], 13 | "homepage": "https://acfwidgets.com/", 14 | "authors": [ 15 | { 16 | "name": "Daron Spence", 17 | "email": "daronspence@gmail.com", 18 | "role": "Lead Developer" 19 | } 20 | ], 21 | "support": { 22 | "issues": "https://acfwidgets.com/support/" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /includes/css/acf-widgets.css: -------------------------------------------------------------------------------- 1 | /*** Widgets.php Admin Page Styles ***/ 2 | .acf-field.field_key-field_acfw_default_widget, .acf-field.field_key-field_acfw_other_widgets { 3 | background: rgba(255, 191, 0, 0.025); 4 | padding: 10px; 5 | border-left: 4px solid lightgreen; 6 | } 7 | /*** CPT Styles ***/ 8 | .post-type-acf-widgets #postexcerpt .inside p { 9 | display: none; 10 | } 11 | .acfw-no-acf[data-display]{ 12 | display: none; 13 | } 14 | /*** Options Page Styles ***/ 15 | .settings_page_acfw-options span { 16 | text-transform: uppercase; 17 | } 18 | .settings_page_acfw-options span.valid{ 19 | color: #7ad03a; 20 | font-weight: bold; 21 | } 22 | .settings_page_acfw-options span.invalid, .settings_page_acfw-options span.expired { 23 | color: red; 24 | } 25 | .settings_page_acfw-options span.deactivated { 26 | color: orange; 27 | } -------------------------------------------------------------------------------- /includes/acf-404.php: -------------------------------------------------------------------------------- 1 | settings['version'], '5.0', '<') ){ 13 | add_action( 'admin_notices', 'acf_404' ); 14 | add_action( 'network_admin_notices', 'acf_404' ); 15 | } 16 | } 17 | 18 | // displays admin warning message 19 | function acf_404() { ?> 20 |
21 |

22 | 23 |

24 |
25 | ', '' ); ?>

2 |

', '', '', $post->post_title, '' ); ?>

3 |

widget-' . $post->post_name . '.php', 'widget-' . $post->ID . '.php' ); ?>

4 |

5 | <?php the_field( '', $acfw ); ?> 6 |

-------------------------------------------------------------------------------- /example-code.php: -------------------------------------------------------------------------------- 1 | value pairs are required. 32 | */ 33 | add_filter('acfw_include_widgets', 'add_include_widgets'); 34 | function add_include_widgets(){ 35 | $acfw_widgets = array( 36 | array( 37 | 'title' => 'Test Widget 1', 38 | 'description' => 'A widget test from functions.php', 39 | 'slug' => 'test-widget', 40 | 'id' => 'Test_Widget', 41 | ), 42 | array( 43 | 'title' => 'Test Widget 2', 44 | 'description' => 'A second widget test from functions.php', 45 | 'slug' => 'test-widget-2', 46 | 'id' => 'Test_Widget2', 47 | ), 48 | ); 49 | return $acfw_widgets; 50 | } -------------------------------------------------------------------------------- /includes/ACFW_Widget_Factory.php: -------------------------------------------------------------------------------- 1 | widgets[$key] = new $widget_class($params); 21 | } else { 22 | do_action( 'acfw_register_widget_in_acfw_widget_factory', $widget_class, $params ); 23 | } 24 | } 25 | 26 | 27 | /** 28 | * Get (and instantiate, if necessary) the instance of the class 29 | * @static 30 | * @return Shared_Sidebars 31 | */ 32 | public static function get_instance() { 33 | if ( !is_a( self::$instance, __CLASS__ ) ) { 34 | self::$instance = new self(); 35 | } 36 | return self::$instance; 37 | } 38 | 39 | final public function __clone() { 40 | trigger_error( "No cloning allowed!", E_USER_ERROR ); 41 | } 42 | 43 | final public function __sleep() { 44 | trigger_error( "No serialization allowed!", E_USER_ERROR ); 45 | } 46 | 47 | public function __construct() { 48 | parent::__construct(); 49 | } 50 | 51 | } 52 | 53 | // End of File -------------------------------------------------------------------------------- /includes/widgets-setup.php: -------------------------------------------------------------------------------- 1 | register( $widget_class, $params ); 24 | } 25 | 26 | 27 | add_action('widgets_init', 'acfw_widgets'); 28 | function acfw_widgets(){ 29 | 30 | $acfw_query = new WP_Query(array( 31 | 'post_type' => 'acf-widgets', 32 | // shouldn't have more than 100 widgets...but just in case 33 | 'posts_per_page' => apply_filters('acfw_query_count', 100), 34 | 'post_status' => 'publish' 35 | )); 36 | 37 | $results = $acfw_query->posts; 38 | 39 | foreach ($results as $result) : 40 | 41 | $params = array(); 42 | 43 | $params['title'] = esc_attr($result->post_title); 44 | $params['description'] = esc_attr($result->post_excerpt); 45 | $params['slug'] = $result->post_name; 46 | $params['id'] = $result->ID; 47 | 48 | //var_dump($params); 49 | 50 | acfw_register_widget('ACFW_Widget', $params); 51 | 52 | endforeach; 53 | 54 | } 55 | 56 | add_action('widgets_init', 'acfw_included_widgets'); 57 | function acfw_included_widgets(){ 58 | 59 | $acfw_included_widgets = apply_filters( 'acfw_include_widgets', array() ); 60 | 61 | if ( !empty($acfw_included_widgets) ) : 62 | 63 | foreach ( $acfw_included_widgets as $widget ): 64 | 65 | $params = array(); 66 | 67 | $params['title'] = esc_attr($widget['title']); 68 | $params['description'] = esc_attr($widget['description']); 69 | $params['slug'] = $widget['slug']; 70 | $params['id'] = $widget['id']; 71 | 72 | acfw_register_widget('ACFW_Widget', $params); 73 | 74 | endforeach; 75 | 76 | endif; 77 | 78 | } 79 | 80 | // End of File 81 | -------------------------------------------------------------------------------- /includes/lang/default.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: acfw\n" 4 | "POT-Creation-Date: 2014-10-27 01:20-0600\n" 5 | "PO-Revision-Date: 2014-10-27 01:21-0600\n" 6 | "Last-Translator: \n" 7 | "Language-Team: \n" 8 | "Language: en\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "X-Generator: Poedit 1.6.10\n" 13 | "X-Poedit-Basepath: ../../\n" 14 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 15 | "X-Poedit-KeywordsList: __;_e\n" 16 | "X-Poedit-SourceCharset: UTF-8\n" 17 | "X-Poedit-SearchPath-0: .\n" 18 | "X-Poedit-SearchPath-1: includes\n" 19 | 20 | #: includes/acf-404.php:15 21 | msgid "" 22 | "ACF Widgets Requires ACF to function. Please activate ACF v5 to remove this " 23 | "message." 24 | msgstr "" 25 | 26 | #: includes/admin-setup.php:24 includes/admin-setup.php:39 27 | #: includes/admin-setup.php:41 28 | msgid "Widgets" 29 | msgstr "" 30 | 31 | #: includes/admin-setup.php:25 32 | msgid "Widgets created with the ACF Widgets Plugin." 33 | msgstr "" 34 | 35 | #: includes/admin-setup.php:40 36 | msgid "Widget" 37 | msgstr "" 38 | 39 | #: includes/admin-setup.php:42 40 | msgid "Add Widget" 41 | msgstr "" 42 | 43 | #: includes/admin-setup.php:43 44 | msgid "Add New Widget" 45 | msgstr "" 46 | 47 | #: includes/admin-setup.php:44 48 | msgid "Edit" 49 | msgstr "" 50 | 51 | #: includes/admin-setup.php:45 52 | msgid "Edit Widget" 53 | msgstr "" 54 | 55 | #: includes/admin-setup.php:46 56 | msgid "New Widget" 57 | msgstr "" 58 | 59 | #: includes/admin-setup.php:47 includes/admin-setup.php:48 60 | msgid "View Widget" 61 | msgstr "" 62 | 63 | #: includes/admin-setup.php:49 64 | msgid "Search Widgets" 65 | msgstr "" 66 | 67 | #: includes/admin-setup.php:50 68 | msgid "No Widgets Found" 69 | msgstr "" 70 | 71 | #: includes/admin-setup.php:51 72 | msgid "No Widgets Found in Trash" 73 | msgstr "" 74 | 75 | #: includes/admin-setup.php:52 76 | msgid "Parent Widget" 77 | msgstr "" 78 | 79 | #: includes/admin-setup.php:61 80 | msgid "ACF Widgets Options" 81 | msgstr "" 82 | 83 | #: includes/admin-setup.php:62 84 | msgid "ACF Widgets" 85 | msgstr "" 86 | 87 | #: includes/default-widgets.php:59 88 | msgid "Custom Field Location" 89 | msgstr "" 90 | 91 | #: includes/default-widgets.php:67 92 | msgid "Before Title" 93 | msgstr "" 94 | 95 | #: includes/default-widgets.php:68 96 | msgid "After Title (title required)" 97 | msgstr "" 98 | 99 | #: includes/default-widgets.php:69 100 | msgid "After Widget" 101 | msgstr "" 102 | -------------------------------------------------------------------------------- /acf-widgets.php: -------------------------------------------------------------------------------- 1 | ACFW_VERSION, // current version number 64 | 'license' => $license_key, // license key (used get_option above to retrieve from DB) 65 | 'item_name' => ACFW_ITEM_NAME, // name of this plugin 66 | 'author' => 'Daron Spence', // author of this plugin 67 | 'url' => home_url() 68 | ) 69 | ); 70 | 71 | } 72 | if(!defined('ACFW_INCLUDE') && get_option('acfw_license_key') != ''){ 73 | add_action( 'admin_init', 'acfw_plugin_updater', 0 ); 74 | } 75 | 76 | register_activation_hook( __FILE__, 'acfw_activate' ); 77 | function acfw_activate(){ 78 | $users = get_users('meta_key=acfw_dismiss_expired'); 79 | foreach ($users as $user) { 80 | delete_user_meta( $user->id, 'acfw_dismiss_expired' ); 81 | } 82 | } 83 | 84 | 85 | // End of File 86 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ACF Widgets 2 | 3 | ## Warning: This plugin is deprecated. 4 | 5 | As of Jan 2023, this plugin is now deprecated. It was a great 8+ year run but I've moved on from working in the WordPress ecosystem. Thank you to everyone who has contributed bug fixes and all of the cool stuff that you built with the plugin over the years. 6 | 7 | -------- 8 | 9 | ACF Widgets (ACFW) allows users to easily create widgets to use with ACF. With ACFW, you can easily create new widgets without touching any code. No PHP classes or dealing with the Widgets API. After you create a widget, you can assign custom fields within ACF and then use theme templates to easily show the custom fields. 10 | 11 | Install: 12 | 13 | * Make sure the latest version of ACF Pro is installed and updated. At the time of this writing, that's 5.2.9 14 | * Upload the .zip from the Plugins menu inside of Wordpress or the unzipped files via S/FTP 15 | * Activate the Plugin 16 | * Click on the new admin menu item called "Add New Widgets" located in the "Appearances" menu. 17 | * Create a new "Widget". 18 | * Create a new field group in ACF. Assign it to the type, "widget" -> "Your widget name". 19 | * Add any fields you want to attach to your new widget. 20 | * Add the widget to a sidebar and fill in your fields. 21 | * Create a new file in your theme directory named `widget-mycool-slug.php`. Alternatively, you can name the template file `widget-id.php` where id is the post id of the widget. (note: `widget-` must be prefixed before the slug of your widget name.) 22 | * NEW! Copy one of the convenient templates from the "templates" directory included in this plugin to your theme folder. 23 | * In your newly created template files, call the fields using the normal methods. See http://www.advancedcustomfields.com/resources/get-values-widget/ for more info. 24 | - Example. `` The `$acfw` variable is automatically mapped for you to use. 25 | * NEW! Template debugging. Navigate to "Settings > ACFW Options" and check the box under debugging. On the front end of your site, any active widgets will tell you what template they are looking for. 26 | 27 |
28 | Old Documentation 29 | 30 | ### Creating New Widgets 31 | 32 | Navigate to Appearance > Add New Widgets and then click Add Widget button next to the title of the page. Give your widget a title and an optional description. After publishing, the widget will be available like any other widget. 33 | 34 | ### Assigning Fields to a Widget 35 | 36 | In the ACF admin area, create a new Field Group. Add any of the fields that you want for your new widget. Then under the Location meta box, set it equal to Widget is equal to Your Custom Widget. The process is identical for 3rd Party Widgets. 37 | 38 | ### Creating & Using Templates 39 | 40 | To show your widgets custom fields, you will first need to create a template file and include it in your theme. You can find the required name for the widget in the admin area of your website. Navigate to Appearance > Add New Widgets and the name of the template is shown in the second column across from the title of it’s respective widget. The normal format of templates is equal to widget-slug.php though you can optionally use widget-id.php. Note, all widget templates are prefixed with widget- and end with a .php extension. For 3rd Party Widgets, only the widget-slug.php template is searched for. You can find the required template name for 3rd Party Widgets by enabling Template Debugging on the Settings > ACFW Options page. For WordPress widgets, there are pre-named templates bundled with the plugin in the templates folder in the plugin root. 41 | 42 | Inside of your templates you can use any combination of tags available to normal PHP files. To retrieve values from your custom fields, you can use the normal ACF API. One example would be 43 | . Note you must pass in the predefined $acfw variable as the second parameter to any ACF function used within widget templates. This tell’s ACF to look for the fields associated with that particular instance of your widget. Since there is no limitation to the amount of widgets that can be shown at any time, this differentiates the widgets from other instances of the same type. 44 | 45 | ### Where to Display Custom Fields 46 | 47 | You will notice that when assigning widgets to a sidebar, standard WordPress Widgets and 3rd Party Widgets have an additional field added by the plugin. For WordPress widgets, you can display your custom fields above the widget, below the title, or below the widget. Since all third party widgets do not include a title field, that option has been removed. 48 |
49 | 50 | If you're interested, the normal filters are still available like $before and $after widget. 51 | 52 | Those with a license can get support from the [Official ACFW Support Forums](http://acfwidgets.com/support/). Priority support is also available for those holding a "Developer" license of the plugin. 53 | 54 | If you're interested in translating, [open an issue](https://github.com/Daronspence/acf-widgets/issues) and we'll work something out :) 55 | -------------------------------------------------------------------------------- /includes/ACFW_Widget.php: -------------------------------------------------------------------------------- 1 | title = $params['title']; 15 | $this->description = $params['description']; 16 | $this->slug = $params['slug']; 17 | $this->post_id = $params['id']; 18 | $this->data_id .= $this->post_id; 19 | 20 | // Deprecated 21 | $old_classname = $this->old_classname(); 22 | 23 | parent::__construct( 24 | $this->data_id, 25 | __( $this->title, 'acfw' ), // Name 26 | array( 27 | 'description' => __( $this->description, 'acfw' ), 28 | 'classname' => $this->data_id . ' ' . $old_classname . ' ' . $this->classes, // class ID + custom stuff 29 | ) // Args 30 | ); 31 | 32 | } 33 | 34 | function form($instance) { 35 | 36 | if ( $this->display_titles() ) : 37 | 38 | $title = empty( $instance['title'] ) ? '' : $instance['title']; ?> 39 | 40 |

41 | 42 | 43 |

44 | 45 | 46 | 47 |

48 | 49 |

50 | 51 | 52 | 53 |

54 | 55 | 56 | 57 | title; ?> 58 | 59 |

60 | 61 | 62 | 63 | display_titles() ) 80 | echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; 81 | 82 | $acfw = 'widget_' . $widget_id ; 83 | 84 | $custom_template_dir = trailingslashit( apply_filters( 'acfw_custom_template_dir', get_template_directory_uri() ) ); 85 | 86 | // var_dump( $custom_template_dir . "widget-{$this->slug}.php" ); 87 | 88 | if ( file_exists( $custom_template_dir . "widget-{$this->slug}.php" ) ) { 89 | require( $custom_template_dir . "widget-{$this->slug}.php" ); 90 | } elseif ( file_exists( $custom_template_dir . "widget-{$this->post_id}.php" ) ){ 91 | require( $custom_template_dir . "widget-{$this->post_id}.php" ); 92 | } elseif (locate_template("widget-{$this->slug}.php") != "") { 93 | require(locate_template("widget-{$this->slug}.php")); 94 | } elseif (locate_template("widget-{$this->post_id}.php") != "") { 95 | require(locate_template("widget-{$this->post_id}.php")); 96 | } else { 97 | echo "No template found for $widget_name "; 98 | } 99 | 100 | echo $after_widget ; 101 | } 102 | 103 | /** 104 | * Returns CSS classname from ACFW < v1.4 105 | * @return string Old Classname 106 | * @deprecated since v1.4 107 | */ 108 | private function old_classname(){ 109 | 110 | $old_classname = explode( '_' , $this->data_id ); 111 | 112 | foreach ( $old_classname as $key => $value ){ 113 | 114 | $old_classname[$key] = ucwords($value); 115 | 116 | } 117 | 118 | $old_classname = implode('_', $old_classname); 119 | 120 | return $old_classname; 121 | } 122 | 123 | /** 124 | * Check for filter to show/hide Widget Titles by default. 125 | * @return bool should titles be displayed? 126 | */ 127 | public function display_titles() { 128 | 129 | if ( apply_filters( "show_acfw_title_{$this->slug}", false ) ) 130 | return true; 131 | elseif ( apply_filters( "hide_acfw_title_{$this->slug}", false ) ) 132 | return false; 133 | elseif ( apply_filters( "show_acfw_title_{$this->post_id}", false ) ) 134 | return true; 135 | elseif ( apply_filters( "hide_acfw_title_{$this->post_id}", false ) ) 136 | return false; 137 | elseif ( apply_filters( "show_acfw_titles" , false ) ) 138 | return true; 139 | elseif ( apply_filters( "hide_acfw_titles" , false ) ) 140 | return false; 141 | else 142 | return false; 143 | 144 | } 145 | } 146 | 147 | // End of File 148 | -------------------------------------------------------------------------------- /includes/helper-functions.php: -------------------------------------------------------------------------------- 1 | $param, 18 | 'operator' => $op, 19 | 'value' => $b 20 | ); 21 | if ($extended){ 22 | // wrap it to denote an "OR" 23 | $push = array($push); 24 | } 25 | $return[] = $push; 26 | } 27 | if (! $extended){ 28 | // wrap it so we don't have to 29 | $return = array($return); 30 | } 31 | return $return; 32 | } 33 | 34 | // Derived from http://php.net/manual/en/function.array-splice.php#111204 35 | // Splice an array and preserve keys 36 | function acfw_array_splice_assoc(&$input, $offset, $length, $replacement = array()) { 37 | $replacement = (array) $replacement; 38 | $key_indices = array_flip(array_keys($input)); 39 | if (isset($input[$offset]) && is_string($offset)) { 40 | $offset = $key_indices[$offset]; 41 | } 42 | if (isset($input[$length]) && is_string($length)) { 43 | $length = $key_indices[$length] - $offset; 44 | } 45 | 46 | $input = array_slice($input, 0, $offset, TRUE) 47 | + $replacement 48 | + array_slice($input, $offset + $length, NULL, TRUE); 49 | } 50 | 51 | // TODO: Use this. 52 | function acfw_settings($key, $value){ 53 | $settings = get_option('acfw_settings'); 54 | $settings[$key] = $value; 55 | update_option('acfw_settings', $settings); 56 | } 57 | 58 | 59 | function acfw_deactivate_license(){ 60 | $api_params = array( 61 | 'edd_action'=> 'deactivate_license', 62 | 'license' => get_option('acfw_license_key'), 63 | 'item_name' => urlencode( ACFW_ITEM_NAME ), 64 | 'url' => home_url() 65 | ); 66 | $deactivate_response = wp_remote_get( add_query_arg( $api_params, ACFW_STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); 67 | $license_data = json_decode( wp_remote_retrieve_body( $deactivate_response ) ); 68 | update_option('acfw_license_status', $license_data->license ); 69 | } 70 | 71 | function acfw_activate_license($lk){ 72 | $api_params = array( 73 | 'edd_action'=> 'activate_license', 74 | 'license' => $lk, 75 | 'item_name' => urlencode( ACFW_ITEM_NAME ), // the name of our product in EDD 76 | 'url' => home_url() 77 | ); 78 | // Call the custom API. 79 | $response = wp_remote_get( add_query_arg( $api_params, ACFW_STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); 80 | 81 | if ( is_wp_error( $response ) ) 82 | return false; 83 | 84 | // decode the license data 85 | $license_data = json_decode( wp_remote_retrieve_body( $response ) ); 86 | 87 | if ($license_data->success == false ){ 88 | update_option('acfw_license_status', 'invalid'); 89 | } 90 | 91 | update_option('acfw_license_status', $license_data->license ); 92 | update_option('acfw_license_count', $license_data->activations_left); 93 | 94 | return $license_data; 95 | } 96 | 97 | function acfw_check_license(){ 98 | if ( defined( 'DOING_AJAX' ) && DOING_AJAX ){ 99 | return; 100 | } 101 | $api_params = array( 102 | 'edd_action' => 'check_license', 103 | 'license' => get_option('acfw_license_key'), 104 | 'item_name' => urlencode( ACFW_ITEM_NAME ), 105 | 'url' => home_url(), 106 | 'request_uri' => $_SERVER['REQUEST_URI'], 107 | 'version' => ACFW_VERSION, 108 | ); 109 | // Call the custom API. 110 | $response = wp_remote_get( add_query_arg( $api_params, ACFW_STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); 111 | 112 | if ( is_wp_error( $response ) ){ 113 | return false; 114 | } 115 | 116 | // decode the license data 117 | $license_data = json_decode( wp_remote_retrieve_body( $response ) ); 118 | 119 | update_option('acfw_license_count', $license_data->activations_left); 120 | update_option('acfw_license_status', $license_data->license); 121 | } 122 | 123 | function acfw_plugins_url($dir, $rel){ 124 | if ( defined('ACFW_INCLUDE') ) 125 | return get_template_directory_uri() . apply_filters('acfw_dir', '/acf-widgets/') . 'includes' . $dir; 126 | else 127 | return plugins_url($dir, $rel); 128 | } 129 | 130 | function acfw_expired_notice(){ 131 | $url = "options-general.php?page=acfw-options"; 132 | if ( is_multisite() ){ 133 | $url = network_admin_url(); 134 | $url = trailingslashit($url) . "settings.php?page=acfw-options"; 135 | } 136 | ob_start(); ?> 137 |
138 |

Your copy of ACF Widgets is expired. Please renew your license to continue recieving updates. Dismiss

139 |
140 | id_base, 'acf_widget') !== false ): ?> 145 |

Sorry, this widget is not availabe to edit from the Customizer. Please go back to the Widgets Page to edit.

146 | 147 |

ACFW Location Rules & ACF Fields are not available within the Customizer. Please go to Widgets.php to edit them.

148 | $filter ) : 158 | if ( ! is_null($priority) && ( (int) $priority !== (int) $p ) ) continue; 159 | $remove = FALSE; 160 | foreach ( $filter as $identifier => $function ) { 161 | $function = $function['function']; 162 | 163 | if ( is_array( $function ) 164 | && ( is_a( $function[0], $class ) || ( is_array( $function ) 165 | && $function[0] === $class ) ) ) : 166 | $remove = ( $method && ( $method === $function[1] ) ); 167 | elseif ( $function instanceof Closure && $class === 'Closure' ) : 168 | $remove = TRUE; 169 | endif; 170 | 171 | if ( $remove ) { 172 | unset( $GLOBALS['wp_filter'][$tag][$p][$identifier] ); 173 | } 174 | } 175 | endforeach; 176 | } 177 | -------------------------------------------------------------------------------- /includes/default-widgets.php: -------------------------------------------------------------------------------- 1 | Looking for template: 'widget-" . $widget_name . ".php'
"; 37 | } 38 | 39 | // Get desired widget position, else default to after widget. 40 | if ( function_exists('get_field') ) : 41 | $select = get_field('acf_widgets_location', 'widget_' . $widget_id); 42 | else : 43 | $select = 'end'; 44 | endif; 45 | 46 | // Attatch template to correct position 47 | $before = $params[0]['before_widget']; 48 | $after = $params[0]['after_title']; 49 | $end = $params[0]['after_widget']; 50 | 51 | if ($select == 'before'){ 52 | $params[0]['before_widget'] = $before . $template; 53 | } elseif ($select == 'after'){ 54 | $params[0]['after_title'] = $after . $template; 55 | } else { 56 | $params[0]['after_widget'] = $template . $end; 57 | } 58 | return $params; 59 | } // end acf_widgets_wp_defaults(); 60 | 61 | 62 | // Add ACFW to WP Widgets w/ before/after title 63 | add_action('init', 'acfw_register_field_group'); 64 | function acfw_register_field_group(){ 65 | 66 | // Bail in WP CLI 67 | if ( defined( 'WP_CLI' ) && WP_CLI ){ 68 | return; 69 | } 70 | 71 | // vars 72 | $default_widgets = $GLOBALS['acfw_default_widgets']; 73 | // Render location for default widgets 74 | $df_widgets = acfw_location_rules($default_widgets, 'widget', '==', true); 75 | 76 | $acf_version = '5.0.0'; 77 | 78 | if ( function_exists('acf') ){ 79 | $acf_version = acf()->version; 80 | } 81 | 82 | if ( version_compare($acf_version, '5.7.10', '>=') ){ 83 | $register_field_group_function = 'acf_add_local_field_group'; 84 | } else { 85 | $register_field_group_function = 'register_field_group'; 86 | } 87 | 88 | if ( class_exists('ACF') ): 89 | $register_field_group_function(array ( 90 | 'key' => 'group_acfw_default_widget', 91 | 'title' => 'ACF Widgets Location', 92 | 'fields' => array ( 93 | array ( 94 | 'key' => 'field_acfw_default_widget', 95 | 'label' => __('Custom Field Location', 'acfw'), 96 | 'name' => 'acf_widgets_location', 97 | 'prefix' => '', 98 | 'type' => 'select', 99 | 'instructions' => '', 100 | 'required' => 0, 101 | 'conditional_logic' => 0, 102 | 'choices' => array ( 103 | 'before' => __('Before Title', 'acfw'), 104 | 'after' => __('After Title (title required)', 'acfw'), 105 | 'end' => __('After Widget', 'acfw'), 106 | ), 107 | 'default_value' => array ( 108 | 'end', 109 | ), 110 | 'allow_null' => 0, 111 | 'multiple' => 0, 112 | 'ui' => 0, 113 | 'ajax' => 0, 114 | 'placeholder' => '', 115 | 'disabled' => 0, 116 | 'readonly' => 0, 117 | ), 118 | ), 119 | // Add to Default Widgets 120 | 'location' => $df_widgets, 121 | 'menu_order' => -1, 122 | 'position' => 'acf_after_title', 123 | 'style' => 'default', 124 | 'label_placement' => 'left', 125 | 'instruction_placement' => 'field', 126 | 'hide_on_screen' => '', 127 | )); 128 | endif; 129 | 130 | } // end acf_widgets_register_field_group() 131 | 132 | 133 | // Add ACFW to non-WP widgets 134 | add_action('init', 'acfw_other_widgets'); 135 | function acfw_other_widgets(){ 136 | 137 | // Bail in WP CLI 138 | if ( defined( 'WP_CLI' ) && WP_CLI ){ 139 | return; 140 | } 141 | 142 | // vars 143 | $installed_widgets = $GLOBALS['wp_widget_factory']->widgets; 144 | $default_widgets = $GLOBALS['acfw_default_widgets']; 145 | 146 | // Remove Default & ACFW widgets 147 | $excluded_widgets = array(); 148 | foreach($installed_widgets as $key => $value){ 149 | if ( strpos($value->id_base, 'acf_widget') !== false ){ 150 | array_push($excluded_widgets, $value->id_base); 151 | } 152 | foreach ($default_widgets as $dw){ 153 | if ($value->id_base == $dw ){ 154 | array_push($excluded_widgets, $value->id_base); 155 | } 156 | } 157 | } 158 | 159 | // Setup widgets for ACF to remove 160 | $removed_widgets = acfw_location_rules($excluded_widgets, 'widget', '!='); 161 | // Add back all other widgets 162 | $all = array( 'param' => 'widget', 'operator' => '==', 'value' => 'all' ); 163 | array_push($removed_widgets[0], $all); 164 | 165 | $acf_version = '5.0.0'; 166 | 167 | if ( function_exists('acf') ){ 168 | $acf_version = acf()->version; 169 | } 170 | 171 | if ( version_compare($acf_version, '5.7.10', '>=') ){ 172 | $register_field_group_function = 'acf_add_local_field_group'; 173 | } else { 174 | $register_field_group_function = 'register_field_group'; 175 | } 176 | 177 | // Register ACFW Field for all other Widgets 178 | if ( class_exists('ACF') ): 179 | $register_field_group_function(array ( 180 | 'key' => 'group_acfw_other_widgets', 181 | 'title' => 'Other Widgets', 182 | 'fields' => array ( 183 | array ( 184 | 'key' => 'field_acfw_other_widgets', 185 | 'label' => __('Custom Fields Location'), 186 | 'name' => 'acf_widgets_location', 187 | 'prefix' => '', 188 | 'type' => 'select', 189 | 'instructions' => '', 190 | 'required' => 0, 191 | 'conditional_logic' => 0, 192 | 'choices' => array ( 193 | 'before' => __('Before Widget'), 194 | 'end' => __('After Widget'), 195 | ), 196 | 'default_value' => array ( 197 | 'end' => 'end', 198 | ), 199 | 'allow_null' => 0, 200 | 'multiple' => 0, 201 | 'ui' => 0, 202 | 'ajax' => 0, 203 | 'placeholder' => '', 204 | 'disabled' => 0, 205 | 'readonly' => 0, 206 | ), 207 | ), 208 | // All Widgets except ACFW & WP 209 | 'location' => $removed_widgets , 210 | 'menu_order' => 0, 211 | 'position' => 'normal', 212 | 'style' => 'default', 213 | 'label_placement' => 'top', 214 | 'instruction_placement' => 'label', 215 | 'hide_on_screen' => '', 216 | ) ); 217 | endif; 218 | 219 | } // End acfw_other_widgets() 220 | 221 | // End of File -------------------------------------------------------------------------------- /EDD_SL_Plugin_Updater.php: -------------------------------------------------------------------------------- 1 | api_url = trailingslashit( $_api_url ); 37 | $this->api_data = $_api_data; 38 | $this->name = plugin_basename( $_plugin_file ); 39 | $this->slug = basename( $_plugin_file, '.php' ); 40 | $this->version = $_api_data['version']; 41 | 42 | $edd_plugin_data[ $this->slug ] = $this->api_data; 43 | 44 | // Set up hooks. 45 | $this->init(); 46 | 47 | } 48 | 49 | /** 50 | * Set up WordPress filters to hook into WP's update process. 51 | * 52 | * @uses add_filter() 53 | * 54 | * @return void 55 | */ 56 | public function init() { 57 | 58 | add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); 59 | add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); 60 | remove_action( 'after_plugin_row_' . $this->name, 'wp_plugin_update_row', 10, 2 ); 61 | add_action( 'after_plugin_row_' . $this->name, array( $this, 'show_update_notification' ), 10, 2 ); 62 | add_action( 'admin_init', array( $this, 'show_changelog' ) ); 63 | 64 | } 65 | 66 | /** 67 | * Check for Updates at the defined API endpoint and modify the update array. 68 | * 69 | * This function dives into the update API just when WordPress creates its update array, 70 | * then adds a custom API call and injects the custom plugin data retrieved from the API. 71 | * It is reassembled from parts of the native WordPress plugin update code. 72 | * See wp-includes/update.php line 121 for the original wp_update_plugins() function. 73 | * 74 | * @uses api_request() 75 | * 76 | * @param array $_transient_data Update array build by WordPress. 77 | * @return array Modified update array with custom plugin data. 78 | */ 79 | function check_update( $_transient_data ) { 80 | 81 | global $pagenow; 82 | 83 | if( ! is_object( $_transient_data ) ) { 84 | $_transient_data = new stdClass; 85 | } 86 | 87 | if( 'plugins.php' == $pagenow && is_multisite() ) { 88 | return $_transient_data; 89 | } 90 | 91 | if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { 92 | 93 | $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); 94 | 95 | if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { 96 | 97 | if( version_compare( $this->version, $version_info->new_version, '<' ) ) { 98 | 99 | $_transient_data->response[ $this->name ] = $version_info; 100 | 101 | } 102 | 103 | $_transient_data->last_checked = time(); 104 | $_transient_data->checked[ $this->name ] = $this->version; 105 | 106 | } 107 | 108 | } 109 | 110 | return $_transient_data; 111 | } 112 | 113 | /** 114 | * show update nofication row -- needed for multisite subsites, because WP won't tell you otherwise! 115 | * 116 | * @param string $file 117 | * @param array $plugin 118 | */ 119 | public function show_update_notification( $file, $plugin ) { 120 | 121 | if( ! current_user_can( 'update_plugins' ) ) { 122 | return; 123 | } 124 | 125 | if( ! is_multisite() ) { 126 | return; 127 | } 128 | 129 | if ( $this->name != $file ) { 130 | return; 131 | } 132 | 133 | // Remove our filter on the site transient 134 | remove_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ), 10 ); 135 | 136 | $update_cache = get_site_transient( 'update_plugins' ); 137 | 138 | $update_cache = is_object( $update_cache ) ? $update_cache : new stdClass(); 139 | 140 | if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { 141 | 142 | $cache_key = md5( 'edd_plugin_' . sanitize_key( $this->name ) . '_version_info' ); 143 | $version_info = get_transient( $cache_key ); 144 | 145 | if( false === $version_info ) { 146 | 147 | $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); 148 | 149 | set_transient( $cache_key, $version_info, 3600 ); 150 | } 151 | 152 | if( ! is_object( $version_info ) ) { 153 | return; 154 | } 155 | 156 | if( version_compare( $this->version, $version_info->new_version, '<' ) ) { 157 | 158 | $update_cache->response[ $this->name ] = $version_info; 159 | 160 | } 161 | 162 | $update_cache->last_checked = time(); 163 | $update_cache->checked[ $this->name ] = $this->version; 164 | 165 | set_site_transient( 'update_plugins', $update_cache ); 166 | 167 | } else { 168 | 169 | $version_info = $update_cache->response[ $this->name ]; 170 | 171 | } 172 | 173 | // Restore our filter 174 | add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); 175 | 176 | if ( ! empty( $update_cache->response[ $this->name ] ) && version_compare( $this->version, $version_info->new_version, '<' ) ) { 177 | 178 | // build a plugin list row, with update notification 179 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); 180 | echo '
'; 181 | 182 | $changelog_link = self_admin_url( 'index.php?edd_sl_action=view_plugin_changelog&plugin=' . $this->name . '&slug=' . $this->slug . '&TB_iframe=true&width=772&height=911' ); 183 | 184 | if ( empty( $version_info->download_link ) ) { 185 | printf( 186 | __( 'There is a new version of %1$s available. View version %3$s details.', 'easy-digital-downloads' ), 187 | esc_html( $version_info->name ), 188 | esc_url( $changelog_link ), 189 | esc_html( $version_info->new_version ) 190 | ); 191 | } else { 192 | printf( 193 | __( 'There is a new version of %1$s available. View version %3$s details or update now.', 'easy-digital-downloads' ), 194 | esc_html( $version_info->name ), 195 | esc_url( $changelog_link ), 196 | esc_html( $version_info->new_version ), 197 | esc_url( wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $this->name, 'upgrade-plugin_' . $this->name ) ) 198 | ); 199 | } 200 | 201 | do_action( "in_plugin_update_message-{$file}", $plugin, $version_info ); 202 | 203 | echo '
'; 204 | } 205 | } 206 | 207 | 208 | /** 209 | * Updates information on the "View version x.x details" page with custom data. 210 | * 211 | * @uses api_request() 212 | * 213 | * @param mixed $_data 214 | * @param string $_action 215 | * @param object $_args 216 | * @return object $_data 217 | */ 218 | function plugins_api_filter( $_data, $_action = '', $_args = null ) { 219 | 220 | 221 | if ( $_action != 'plugin_information' ) { 222 | 223 | return $_data; 224 | 225 | } 226 | 227 | if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { 228 | 229 | return $_data; 230 | 231 | } 232 | 233 | $to_send = array( 234 | 'slug' => $this->slug, 235 | 'is_ssl' => is_ssl(), 236 | 'fields' => array( 237 | 'banners' => false, // These will be supported soon hopefully 238 | 'reviews' => false 239 | ) 240 | ); 241 | 242 | $api_response = $this->api_request( 'plugin_information', $to_send ); 243 | 244 | if ( false !== $api_response ) { 245 | $_data = $api_response; 246 | } 247 | 248 | return $_data; 249 | } 250 | 251 | 252 | /** 253 | * Disable SSL verification in order to prevent download update failures 254 | * 255 | * @param array $args 256 | * @param string $url 257 | * @return object $array 258 | */ 259 | function http_request_args( $args, $url ) { 260 | // If it is an https request and we are performing a package download, disable ssl verification 261 | if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { 262 | $args['sslverify'] = false; 263 | } 264 | return $args; 265 | } 266 | 267 | /** 268 | * Calls the API and, if successfull, returns the object delivered by the API. 269 | * 270 | * @uses get_bloginfo() 271 | * @uses wp_remote_post() 272 | * @uses is_wp_error() 273 | * 274 | * @param string $_action The requested action. 275 | * @param array $_data Parameters for the API action. 276 | * @return false|object 277 | */ 278 | private function api_request( $_action, $_data ) { 279 | 280 | global $wp_version; 281 | 282 | $data = array_merge( $this->api_data, $_data ); 283 | 284 | if ( $data['slug'] != $this->slug ) { 285 | return; 286 | } 287 | 288 | if( $this->api_url == home_url() ) { 289 | return false; // Don't allow a plugin to ping itself 290 | } 291 | 292 | $api_params = array( 293 | 'edd_action' => 'get_version', 294 | 'license' => ! empty( $data['license'] ) ? $data['license'] : '', 295 | 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, 296 | 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, 297 | 'slug' => $data['slug'], 298 | 'author' => $data['author'], 299 | 'url' => home_url() 300 | ); 301 | 302 | $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); 303 | 304 | if ( ! is_wp_error( $request ) ) { 305 | $request = json_decode( wp_remote_retrieve_body( $request ) ); 306 | } 307 | 308 | if ( $request && isset( $request->sections ) ) { 309 | $request->sections = maybe_unserialize( $request->sections ); 310 | } else { 311 | $request = false; 312 | } 313 | 314 | return $request; 315 | } 316 | 317 | public function show_changelog() { 318 | 319 | global $edd_plugin_data; 320 | 321 | if( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { 322 | return; 323 | } 324 | 325 | if( empty( $_REQUEST['plugin'] ) ) { 326 | return; 327 | } 328 | 329 | if( empty( $_REQUEST['slug'] ) ) { 330 | return; 331 | } 332 | 333 | if( ! current_user_can( 'update_plugins' ) ) { 334 | wp_die( __( 'You do not have permission to install plugin updates', 'easy-digital-downloads' ), __( 'Error', 'easy-digital-downloads' ), array( 'response' => 403 ) ); 335 | } 336 | 337 | $data = $edd_plugin_data[ $_REQUEST['slug'] ]; 338 | $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_version_info' ); 339 | $version_info = get_transient( $cache_key ); 340 | 341 | if( false === $version_info ) { 342 | 343 | $api_params = array( 344 | 'edd_action' => 'get_version', 345 | 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, 346 | 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, 347 | 'slug' => $_REQUEST['slug'], 348 | 'author' => $data['author'], 349 | 'url' => home_url() 350 | ); 351 | 352 | $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); 353 | 354 | if ( ! is_wp_error( $request ) ) { 355 | $version_info = json_decode( wp_remote_retrieve_body( $request ) ); 356 | } 357 | 358 | if ( ! empty( $version_info ) && isset( $version_info->sections ) ) { 359 | $version_info->sections = maybe_unserialize( $version_info->sections ); 360 | } else { 361 | $version_info = false; 362 | } 363 | 364 | set_transient( $cache_key, $version_info, 3600 ); 365 | 366 | } 367 | 368 | if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) { 369 | echo '
' . $version_info->sections['changelog'] . '
'; 370 | } 371 | 372 | exit; 373 | } 374 | 375 | } -------------------------------------------------------------------------------- /includes/admin-setup.php: -------------------------------------------------------------------------------- 1 | __('ACF Widgets', 'acfw'), 32 | 'description' => __('Widgets created with the ACF Widgets Plugin.', 'acfw'), 33 | 'public' => false, 34 | 'show_ui' => true, 35 | 'show_in_menu' => $menu_location, 36 | 'capability_type' => 'post', 37 | 'map_meta_cap' => true, 38 | 'hierarchical' => false, 39 | 'rewrite' => array('slug' => 'acf-widgets', 'with_front' => true), 40 | 'query_var' => true, 41 | 'exclude_from_search' => true, 42 | 'menu_position' => 8, 43 | 'menu_icon' => 'dashicons-screenoptions', 44 | 'supports' => array('title', 'excerpt'), 45 | 'labels' => array ( 46 | 'name' => __('Widgets', 'acfw'), 47 | 'singular_name' => __('ACF Widget', 'acfw'), 48 | 'menu_name' => __('Add New Widgets', 'acfw'), 49 | 'add_new' => __('Add Widget', 'acfw'), 50 | 'add_new_item' => __('Add New Widget', 'acfw'), 51 | 'edit' => __('Edit', 'acfw'), 52 | 'edit_item' => __('Edit Widget', 'acfw'), 53 | 'new_item' => __('New Widget', 'acfw'), 54 | 'view' => __('View Widget', 'acfw'), 55 | 'view_item' => __('View Widget', 'acfw'), 56 | 'search_items' => __('Search Widgets', 'acfw'), 57 | 'not_found' => __('No Widgets Found', 'acfw'), 58 | 'not_found_in_trash' => __('No Widgets Found in Trash', 'acfw'), 59 | 'parent' => __('Parent Widget', 'acfw'), 60 | ) 61 | ) ); 62 | } // end acfw_register_cpt() 63 | 64 | // Add How-To Metabox to Widgets CPT 65 | add_action( 'add_meta_boxes', 'acfw_widget_meta_boxes' ); 66 | function acfw_widget_meta_boxes() { 67 | add_meta_box( 68 | 'acfw-helper-text', 69 | __( 'Using ACF Widgets in Your Theme', 'acfw' ), 70 | 'acfw_how_to_meta_box', 71 | 'acf-widgets' 72 | ); 73 | } 74 | // Display contents of the helper metabox 75 | function acfw_how_to_meta_box( $post ) { 76 | $title = $post->post_title; 77 | if ($title == ''){ 78 | _e('For more information, give your widget a title, then Publish or Update this page.', 'acfw'); 79 | } else { 80 | include( 'views/how-to-meta-box.php' ); 81 | } 82 | } 83 | 84 | 85 | 86 | // ACFW Support Meta Box 87 | add_action('add_meta_boxes_acf-widgets', 'acfw_support_meta_box'); 88 | 89 | function acfw_support_meta_box(){ 90 | 91 | add_meta_box('acfw-support', __('Support', 'acfw'), 'acfw_support_meta_box_html', 'acf-widgets', 'side'); 92 | 93 | } 94 | 95 | function acfw_support_meta_box_html(){ 96 | 97 | include( 'views/support-meta-box.php' ); 98 | 99 | } 100 | // End Support Meta Box 101 | 102 | // Add ACFW Options Page 103 | add_action('admin_menu','acfw_menu_items'); 104 | add_action('network_admin_menu', 'acfw_menu_items'); 105 | function acfw_menu_items(){ 106 | if ( !defined('ACFW_LITE') && current_user_can('manage_options') ){ 107 | add_options_page( 'ACFW Options', 'ACFW Options', 'edit_posts', 'acfw-options', 'acfw_options_page' ); 108 | if ( is_network_admin() ) 109 | add_submenu_page( 'settings.php', 'ACFW Options', 'ACFW Options', 'edit_posts', 'acfw-options', 'acfw_options_page' ); 110 | } 111 | } 112 | function acfw_options_page(){ 113 | if(isset($_POST['_wpnonce'])){ 114 | if ( wp_verify_nonce( $_POST['_wpnonce'], 'acfw_options_nonce' ) ){ 115 | 116 | // LICENSE STUFF // 117 | if ( isset( $_POST['deactivate'] ) ){ 118 | 119 | acfw_deactivate_license(); 120 | update_option( 'acfw_license_key', ''); 121 | 122 | } elseif ( isset( $_POST['activate'] ) ){ 123 | 124 | $status = acfw_activate_license(trim($_POST['acfwlicensekey'])); 125 | 126 | if ( $status->license != 'invalid' || $status->error == 'expired'){ 127 | update_option( 'acfw_license_key', trim( $_POST['acfwlicensekey'] ) ); 128 | } 129 | 130 | if ( $status->success === false && $status->error === 'no_activations_left' ){ 131 | $error_message = __( 'You have no activations remaining.', 'acfw' ); 132 | } 133 | 134 | } 135 | 136 | // DEBUG STUFF // 137 | if ( isset($_POST['acfwdebug']) ){ 138 | update_option( 'acfw_debug', $_POST['acfwdebug'] ); 139 | } else { 140 | update_option( 'acfw_debug', 0 ); 141 | } 142 | } 143 | } 144 | $key = get_option('acfw_license_key'); 145 | if (!empty($key)) 146 | acfw_check_license(); 147 | 148 | $status = get_option('acfw_license_status'); 149 | $count = get_option('acfw_license_count'); 150 | $key_input_type = strlen( $key ) > 0 ? 'password' : 'text'; 151 | 152 | ?> 153 |
154 |

ACFW Options

155 |
156 | 157 |
158 |
159 |
160 |
161 |

License Key

162 |
163 |

Enter your license key below.

164 | 165 | While your license is either deactivated or invalid, you will not recieve any updates.

'; 171 | } 172 | echo '

' . 'License Key: ' . "" . $status . '

'; 173 | if ( isset( $error_message ) ){ 174 | echo "

" . $error_message . "

"; 175 | } 176 | if( $count === '0' && ($status == 'expired' || $status == 'valid') ){ 177 | echo '

You have no more licenses remaining. Consider deactivating some or purchasing a developers license.

'; 178 | } elseif ( $count == 'unlimited' && ($status == 'expired' || $status == 'valid') ){ 179 | echo '

Thank you for purchasing a developer license! If you need help, check out the Priority Support Forums.

'; 180 | } 181 | if($status == 'expired'){ 182 | echo '

Your license has expired.

Renew Your License & Get 20% Off

'; 183 | } ?> 184 | 185 | 186 | 187 | 188 | 189 |
190 |
191 |
192 |

Template Debug

193 |
194 | /> 195 |

View the filename of the required template on the front end of your site when the widget is currently active. Usually used for default WP or 3rd Party Widgets.

196 |
197 |
198 |
199 |
200 |
201 |

Support

202 |
203 | 204 |
205 |
206 |
207 |
208 |
209 | 210 |
211 |
212 |
213 | Widgets 217 | add_action('admin_menu', 'acfw_edit_admin_menu', 10); 218 | function acfw_edit_admin_menu(){ 219 | if ( !current_user_can('manage_options') ) 220 | return; 221 | 222 | global $submenu; 223 | 224 | if ( empty( $submenu['themes.php'][7] ) ){ 225 | return; // return if the default menu structure has been modified 226 | } 227 | 228 | $widgets_postion[7] = $submenu['themes.php'][7]; // preserve key for widgets.php 229 | $widgets_postion[] = array_pop($submenu['themes.php']); 230 | // Splice and preserve keys 231 | acfw_array_splice_assoc($submenu['themes.php'], 2, 1, $widgets_postion); 232 | } // end acfw_edit_admin_menu() 233 | 234 | // Custom Columns For ACFW CPT 235 | add_action( 'manage_acf-widgets_posts_custom_column' , 'acfw_custom_column', 10, 2 ); 236 | 237 | function acfw_custom_column($column, $post_id){ 238 | $name = get_post( $post_id )->post_name; 239 | echo 'widget-' . $name . '.php'; 240 | } 241 | 242 | add_filter('manage_acf-widgets_posts_columns' , 'acfw_add_columns'); 243 | 244 | function acfw_add_columns($columns){ 245 | unset($columns['date']); 246 | $columns['template'] = __('Theme Template', 'acfw'); 247 | return $columns; 248 | } // End custom columns 249 | 250 | // ACFW CPT title 251 | add_filter('enter_title_here', 'acfw_cpt_title'); 252 | function acfw_cpt_title( $title ){ 253 | $screen = get_current_screen(); 254 | if ('acf-widgets' == $screen->post_type){ 255 | $title = __('Enter widget name', 'acfw' ); 256 | } return $title; 257 | } // End acfw_cpt_title() 258 | 259 | // Filter Excerpt Title 260 | add_filter( 'gettext', 'acfw_custom_excerpt_title' ); 261 | function acfw_custom_excerpt_title( $input ) { 262 | global $post_type; 263 | if ( is_admin() && 'acf-widgets' == $post_type && 'Excerpt' == $input ){ 264 | return __( 'Widget Description', 'acfw' ); 265 | } 266 | return $input; 267 | } // End CPT title rewrite 268 | 269 | // Update Slug When Saving CPT Title 270 | add_filter( 'wp_insert_post_data', 'acfw_update_slug', 50, 2 ); 271 | function acfw_update_slug( $data, $postarr ) { 272 | if ( !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft', 'revision' ) ) && $data['post_type'] == 'acf-widgets' ) { 273 | $data['post_name'] = sanitize_title( $data['post_title'] ); 274 | } 275 | return $data; 276 | } // end CPT slug rewrite 277 | 278 | // Check license once on login 279 | add_action('wp_login', 'acfw_login_check', 10, 2); 280 | function acfw_login_check($login, $user){ 281 | if ( isset( $user->allcaps['update_plugins'] ) && $user->allcaps['update_plugins'] && ! defined('ACFW_INCLUDE') ){ 282 | acfw_check_license(); 283 | } 284 | } // end login license check 285 | 286 | // Display ACFW notices 287 | add_action( 'admin_init', 'acfw_admin_notices' ); 288 | function acfw_admin_notices(){ 289 | if ( ( isset($_GET['page']) && $_GET['page'] == 'acfw-options' ) || defined('ACFW_INCLUDE') || defined('ACFW_LITE') ) 290 | return; 291 | 292 | global $current_user; 293 | $user_id = $current_user->ID; 294 | $dismissed = get_user_meta($user_id, 'acfw_dismiss_expired'); 295 | 296 | if ( !empty($dismissed) ) { 297 | if ( $dismissed[0] !== ACFW_VERSION ) // Show expired message if they updated the plugin 298 | delete_user_meta( $user_id, 'acfw_dismiss_expired' ); 299 | } 300 | 301 | if ( isset($_GET['acfw-dismiss-expired']) && $_GET['acfw-dismiss-expired'] == '1' ) 302 | update_user_meta( $user_id, 'acfw_dismiss_expired', ACFW_VERSION ); 303 | 304 | if ( empty( $dismissed ) ){ 305 | 306 | if ( get_option('acfw_license_status') == 'expired' && ! $dismissed && current_user_can('update_plugins') ){ 307 | add_action('admin_notices', 'acfw_expired_notice'); 308 | add_action('network_admin_notices', 'acfw_expired_notice'); 309 | } 310 | 311 | } 312 | 313 | global $pagenow; 314 | if ( $pagenow == 'plugins.php' && !defined('ACFW_INCLUDE') ){ 315 | add_action("after_plugin_row_" . plugin_basename(ACFW_FILE), 'acfw_plugins_page_info', 11, 3); 316 | } 317 | } // End ACFW notices 318 | 319 | function acfw_plugins_page_info(){ 320 | $status = get_option('acfw_license_status'); 321 | if ( $status == 'valid' ) 322 | return; 323 | 324 | $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); 325 | $key = get_option('acfw_license_key'); 326 | $acfw_message = ''; 327 | 328 | if ( $status == 'expired' ) 329 | $acfw_message .= 'Your ACFW license is expired. Renew it now to continue receiving updates & support.'; 330 | if ( ($status == 'invalid' || $key == '') && !defined('ACFW_LITE') ) 331 | $acfw_message .= 'It seems like there is a problem with your ACFW license. Check your options in Settings > ACFW Options'; 332 | 333 | echo "
{$acfw_message}
"; 334 | } 335 | 336 | 337 | add_action('admin_head', 'acfw_lite_css'); 338 | function acfw_lite_css(){ 339 | 340 | if ( defined('ACFW_LITE') ) 341 | echo ""; 342 | 343 | } 344 | // End of File --------------------------------------------------------------------------------