Changeset 2516947
- Timestamp:
- 04/17/2021 08:48:02 PM (5 years ago)
- Location:
- presets
- Files:
-
- 10 added
- 18 edited
- 1 copied
-
tags/0.2.0 (copied) (copied from presets/trunk)
-
tags/0.2.0/presets.php (modified) (1 diff)
-
tags/0.2.0/readme.md (modified) (1 diff)
-
tags/0.2.0/readme.txt (modified) (2 diffs)
-
tags/0.2.0/src/actions/apply-presets.php (modified) (2 diffs)
-
tags/0.2.0/src/actions/core/plugins.php (added)
-
tags/0.2.0/src/actions/core/user.php (modified) (1 diff)
-
tags/0.2.0/src/metabox/core/plugins.php (added)
-
tags/0.2.0/src/metabox/core/user.php (modified) (1 diff)
-
tags/0.2.0/src/metabox/presets-options.php (modified) (2 diffs)
-
tags/0.2.0/src/settings (added)
-
tags/0.2.0/src/settings/advanced-settings.php (added)
-
tags/0.2.0/src/settings/helpers.php (added)
-
tags/0.2.0/src/triggers/triggers.php (modified) (1 diff)
-
tags/0.2.0/src/triggers/wp-admin-bar/trigger.php (modified) (4 diffs)
-
trunk/presets.php (modified) (1 diff)
-
trunk/readme.md (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/src/actions/apply-presets.php (modified) (2 diffs)
-
trunk/src/actions/core/plugins.php (added)
-
trunk/src/actions/core/user.php (modified) (1 diff)
-
trunk/src/metabox/core/plugins.php (added)
-
trunk/src/metabox/core/user.php (modified) (1 diff)
-
trunk/src/metabox/presets-options.php (modified) (2 diffs)
-
trunk/src/settings (added)
-
trunk/src/settings/advanced-settings.php (added)
-
trunk/src/settings/helpers.php (added)
-
trunk/src/triggers/triggers.php (modified) (1 diff)
-
trunk/src/triggers/wp-admin-bar/trigger.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
presets/tags/0.2.0/presets.php
r2513575 r2516947 2 2 /** 3 3 * Plugin Name: Presets 4 * Description: The Presets plugin allows you to fill your WordPress with demo data in just a few seconds allowing you to test it without the need to manually change the settings every time.4 * Description: The Presets plugin allows you to fill your WordPress with specific predefined settings in just a few seconds. 5 5 * Author: Presets contributors 6 6 * Author URI: https://github.com/felipelousantos/wp-presets/graphs/contributors 7 7 * Text Domain: presets 8 * Version: 0. 1.08 * Version: 0.2.0 9 9 * 10 10 * @package Presets 11 11 */ 12 12 13 14 /** 15 * Function outputs the plugin directory with the root file name. 16 * 17 */ 18 function presets_plugin_filename() { 19 return str_replace( plugin_dir_path( __DIR__ ), '', $dir = plugin_dir_path( __FILE__ ) ) . 'presets.php'; 20 } 21 13 22 require_once plugin_dir_path( __FILE__ ) . 'src/cpt/presets.php'; 14 23 require_once plugin_dir_path( __FILE__ ) . 'src/taxonomy/presets-tags.php'; 24 require_once plugin_dir_path( __FILE__ ) . 'src/settings/advanced-settings.php'; 25 require_once plugin_dir_path( __FILE__ ) . 'src/settings/helpers.php'; 15 26 require_once plugin_dir_path( __FILE__ ) . 'src/metabox/presets-options.php'; 16 27 require_once plugin_dir_path( __FILE__ ) . 'src/triggers/triggers.php'; -
presets/tags/0.2.0/readme.md
r2513575 r2516947 1 Presets is a WordPress plugin that allows you to fill your WordPress with previously defined demo/test data in just a few seconds allowing you to test it without the need to manually change the settings every time. 1 The Presets plugin allows you to fill your WordPress with previously defined settings in just a few seconds allowing you to test it without the need to manually change the settings every time. 2 3 Currently, you are able to change WordPress user meta details and define plugins to be activated/deactivate when a preset is triggered, but the goal will be to bring more WordPress and WooCommerce settings. We hope to make it easy in the long term to extend and bring more plugins settings. 2 4 3 5 This plugin hasn't been developed to be working on production sites. The goal with it is mostly to allow you to test plugins that require you to change the settings all the time. 4 5 Currently, you are only able to change WordPress user meta details, but the goal will be to bring more WordPress and WooCommerce settings. We hope to make it easy in the long term to extend and bring more plugins settings. -
presets/tags/0.2.0/readme.txt
r2513575 r2516947 5 5 Tested up to: 5.7 6 6 Requires PHP: 7.0 7 Stable tag: 0. 1.07 Stable tag: 0.2.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 The Presets plugin allows you to fill your WordPress with demo data in just a few seconds allowing you to test it without the need to manually change the settings every time.11 The Presets plugin allows you to fill your WordPress with specific predefined settings in just a few seconds. 12 12 13 13 == Description == 14 14 15 The Presets plugin allows you to fill your WordPress with previously defined demo/test data in just a few seconds allowing you to test it without the need to manually change the settings every time. 15 The Presets plugin allows you to fill your WordPress with previously defined settings in just a few seconds allowing you to test it without the need to manually change the settings every time. 16 17 Currently, you are able to change WordPress user meta details and define plugins to be activated/deactivate when a preset is triggered, but the goal will be to bring more WordPress and WooCommerce settings. We hope to make it easy in the long term to extend and bring more plugins settings. 16 18 17 19 This plugin hasn't been developed to be working on production sites. The goal with it is mostly to allow you to test plugins that require you to change the settings all the time. 18 19 Currently, you are only able to change WordPress user meta details, but the goal will be to bring more WordPress and WooCommerce settings. We hope to make it easy in the long term to extend and bring more plugins settings.20 20 21 21 == Installation == … … 29 29 30 30 That plugin is not for production sites. it means that it won't probably make sense if you want to use it on your live site. It was created mostly with support teams and maybe even developers in mind that need to test things quickly and changing specific settings is required for that. 31 31 32 == Changelog == 33 34 = 0.2.0 = 35 Added the Plugins Module allowing you to activate/deactivate plugins when the preset is triggered. 32 36 33 37 = 0.1.0 = -
presets/tags/0.2.0/src/actions/apply-presets.php
r2513575 r2516947 2 2 3 3 require_once plugin_dir_path( __FILE__ ) . 'core/user.php'; 4 require_once plugin_dir_path( __FILE__ ) . 'core/plugins.php'; 4 5 5 6 function get_presets_meta( $prefix, $field ) { 6 $selected_presets_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT ); 7 return get_post_meta( $selected_presets_id, 'presets_' . $prefix . $field, true ); 8 } 9 10 function presets_admin_notice__success() { ?> 11 <div class="notice notice-success is-dismissible"> 12 <p><?php _e( 'The settings were applied as expected! ', 'presets' ); ?></p> 13 </div> 14 <?php 7 $preset_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT ); 8 return get_post_meta( $preset_id, 'presets_' . $prefix . $field, true ); 15 9 } 16 10 … … 21 15 } 22 16 23 $ selected_presets_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT );17 $preset_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT ); 24 18 25 if ( get_post_type( $ selected_presets_id ) !== 'presets' ) {19 if ( get_post_type( $preset_id ) !== 'presets' ) { 26 20 return; 27 21 } 28 22 29 presets_core_user_apply_meta(); 30 31 add_action( 'admin_notices', 'presets_admin_notice__success' ); 23 /** 24 * presets_apply_meta hook. 25 * 26 * @hooked presets_core_user_apply_meta 27 * @hooked presets_core_plugins_apply_meta 28 */ 29 do_action( 'presets_apply_meta' ); 32 30 33 31 } 34 32 35 add_action( 'admin_head', 'apply_presets' ); 33 add_action( 'admin_init', 'apply_presets', 10 ); 34 35 /** 36 * Redirect after presets have been applied. 37 */ 38 function presets_apply_redirection() { 39 40 if ( ! isset( $_GET['presets-trigger'] ) || ! current_user_can( 'manage_options' ) ) { 41 return; 42 } 43 44 $preset_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT ); 45 46 $redirect_url = add_query_arg( 'presets-applied', $preset_id, remove_query_arg( 'presets-trigger', $_SERVER['REQUEST_URI'] ) ); 47 48 wp_safe_redirect( $redirect_url ); 49 exit; 50 51 } 52 53 add_action( 'admin_init', 'presets_apply_redirection', 20 ); 54 55 /** 56 * Display notice after action confirmation. 57 */ 58 function presets_admin_notice__success() { 59 60 if ( ! isset( $_GET['presets-applied'] ) || ! current_user_can( 'manage_options' ) ) { 61 return; 62 } 63 64 ?> 65 <div class="notice notice-success is-dismissible"> 66 <p><?php _e( 'The settings were applied as expected! ', 'presets' ); ?></p> 67 </div> 68 <?php 69 } 70 71 add_action( 'admin_notices', 'presets_admin_notice__success' ); -
presets/tags/0.2.0/src/actions/core/user.php
r2513575 r2516947 27 27 28 28 } 29 30 add_action( 'presets_apply_meta', 'presets_core_user_apply_meta' ); -
presets/tags/0.2.0/src/metabox/core/user.php
r2513575 r2516947 1 1 <?php 2 2 3 $prefix_meta = $prefix . 'core_user_'; 3 function presets_core_user_create_metabox() { 4 4 5 /** 6 * Initiate the metabox 7 */ 8 $cmb = new_cmb2_box( 9 array( 10 'id' => $prefix_meta . 'metabox', 11 'title' => __( '[Core] Current user', 'presets' ), 12 'object_types' => array( 'presets' ), // Post type 13 'context' => 'normal', 14 'priority' => 'high', 15 'show_names' => true, // Show field names on the left 16 // 'cmb_styles' => false, // false to disable the CMB stylesheet 17 // 'closed' => true, // Keep the metabox closed by default 18 ) 19 ); 5 $prefix_meta = 'presets_core_user_'; 20 6 21 $cmb->add_field( 22 array( 23 'name' => __( 'First Name', 'presets' ), 24 'id' => $prefix_meta . 'first_name', 25 'type' => 'text', 26 ) 27 ); 7 /** 8 * Initiate the metabox 9 */ 10 $cmb = new_cmb2_box( 11 array( 12 'id' => $prefix_meta . 'metabox', 13 'title' => __( '[Core] Current user', 'presets' ), 14 'object_types' => array( 'presets' ), // Post type 15 'context' => 'normal', 16 'priority' => 'high', 17 'show_names' => true, // Show field names on the left 18 // 'cmb_styles' => false, // false to disable the CMB stylesheet 19 // 'closed' => true, // Keep the metabox closed by default 20 ) 21 ); 28 22 29 $cmb->add_field(30 array(31 'name' => __( 'Last Name', 'presets' ),32 'id' => $prefix_meta . 'last_name',33 'type' => 'text',34 )35 );23 $cmb->add_field( 24 array( 25 'name' => __( 'First Name', 'presets' ), 26 'id' => $prefix_meta . 'first_name', 27 'type' => 'text', 28 ) 29 ); 36 30 37 $cmb->add_field(38 array(39 'name' => __( 'DisplayName', 'presets' ),40 'id' => $prefix_meta . 'display_name',41 'type' => 'text',42 )43 );31 $cmb->add_field( 32 array( 33 'name' => __( 'Last Name', 'presets' ), 34 'id' => $prefix_meta . 'last_name', 35 'type' => 'text', 36 ) 37 ); 44 38 45 $cmb->add_field(46 array(47 'name' => __( 'Website', 'presets' ),48 'id' => $prefix_meta . 'user_url',49 'type' => 'text_url',50 )51 );39 $cmb->add_field( 40 array( 41 'name' => __( 'Display Name', 'presets' ), 42 'id' => $prefix_meta . 'display_name', 43 'type' => 'text', 44 ) 45 ); 52 46 53 $cmb->add_field(54 array(55 'name' => __( 'Email', 'presets' ),56 'id' => $prefix_meta . 'user_email',57 'type' => 'text_email',58 )59 );47 $cmb->add_field( 48 array( 49 'name' => __( 'Website', 'presets' ), 50 'id' => $prefix_meta . 'user_url', 51 'type' => 'text_url', 52 ) 53 ); 60 54 61 $cmb->add_field( 62 array( 63 'name' => __( 'Bio', 'presets' ), 64 'id' => $prefix_meta . 'description', 65 'type' => 'textarea', 66 ) 67 ); 55 $cmb->add_field( 56 array( 57 'name' => __( 'Email', 'presets' ), 58 'id' => $prefix_meta . 'user_email', 59 'type' => 'text_email', 60 ) 61 ); 62 63 $cmb->add_field( 64 array( 65 'name' => __( 'Bio', 'presets' ), 66 'id' => $prefix_meta . 'description', 67 'type' => 'textarea', 68 ) 69 ); 70 71 } 72 73 add_action( 'presets_create_metabox', 'presets_core_user_create_metabox' ); -
presets/tags/0.2.0/src/metabox/presets-options.php
r2513575 r2516947 2 2 3 3 /** 4 * Adding 'cmb2' vendor 4 * Adding 'cmb2' vendor. 5 5 */ 6 6 if ( file_exists( dirname( __FILE__ ) . '/../../vendors/cmb2/init.php' ) ) { … … 8 8 } 9 9 10 11 include_once plugin_dir_path( __FILE__ ) . 'core/user.php'; 12 include_once plugin_dir_path( __FILE__ ) . 'core/plugins.php'; 13 14 /** 15 * Create metabox. 16 */ 10 17 function presets_options() { 11 18 12 19 $prefix = 'presets_'; 13 20 14 include_once plugin_dir_path( __FILE__ ) . 'core/user.php'; 21 /** 22 * presets_create_metabox hook. 23 * 24 * @hooked presets_core_user_create_metabox 25 * @hooked presets_core_plugins_create_metabox 26 */ 27 do_action( 'presets_create_metabox' ); 15 28 16 29 } -
presets/tags/0.2.0/src/triggers/triggers.php
r2513575 r2516947 2 2 3 3 include_once plugin_dir_path( __FILE__ ) . 'wp-admin-bar/trigger.php'; 4 5 function presets_get_ids() { 6 7 return get_posts( 8 array( 9 'fields' => 'ids', 10 'posts_per_page' => -1, 11 'post_type' => 'presets', 12 ) 13 ); 14 15 } 16 17 function presets_get_current_url( $id ) { 18 19 return add_query_arg( 'presets-trigger', $id, $_SERVER['REQUEST_URI'] ); 20 21 } -
presets/tags/0.2.0/src/triggers/wp-admin-bar/trigger.php
r2513575 r2516947 6 6 return; 7 7 } 8 8 9 $admin_bar->add_menu( 9 10 array( … … 19 20 ); 20 21 21 $presets_ids = get_posts( 22 array( 23 'fields' => 'ids', 24 'posts_per_page' => -1, 25 'post_type' => 'presets', 26 ) 27 ); 28 29 foreach ( $presets_ids as $id ) { 22 foreach ( presets_get_ids() as $id ) { 30 23 31 24 $admin_bar->add_menu( … … 35 28 'group' => null, 36 29 'title' => get_the_title( $id ), // you can use img tag with image link. it will show the image icon Instead of the title. 37 'href' => admin_url( 'edit.php?post_type=presets&presets-trigger=' .$id ),30 'href' => presets_get_current_url( $id ), 38 31 'meta' => array( 39 32 'title' => get_the_title( $id ), // This title will show on hover. … … 46 39 } 47 40 48 add_action( 'admin_bar_menu', 'presets_admin_bar_item', 100 ); 41 add_action( 42 'admin_init', 43 function () { 44 add_action( 'admin_bar_menu', 'presets_admin_bar_item', 100 ); 45 } 46 ); -
presets/trunk/presets.php
r2513575 r2516947 2 2 /** 3 3 * Plugin Name: Presets 4 * Description: The Presets plugin allows you to fill your WordPress with demo data in just a few seconds allowing you to test it without the need to manually change the settings every time.4 * Description: The Presets plugin allows you to fill your WordPress with specific predefined settings in just a few seconds. 5 5 * Author: Presets contributors 6 6 * Author URI: https://github.com/felipelousantos/wp-presets/graphs/contributors 7 7 * Text Domain: presets 8 * Version: 0. 1.08 * Version: 0.2.0 9 9 * 10 10 * @package Presets 11 11 */ 12 12 13 14 /** 15 * Function outputs the plugin directory with the root file name. 16 * 17 */ 18 function presets_plugin_filename() { 19 return str_replace( plugin_dir_path( __DIR__ ), '', $dir = plugin_dir_path( __FILE__ ) ) . 'presets.php'; 20 } 21 13 22 require_once plugin_dir_path( __FILE__ ) . 'src/cpt/presets.php'; 14 23 require_once plugin_dir_path( __FILE__ ) . 'src/taxonomy/presets-tags.php'; 24 require_once plugin_dir_path( __FILE__ ) . 'src/settings/advanced-settings.php'; 25 require_once plugin_dir_path( __FILE__ ) . 'src/settings/helpers.php'; 15 26 require_once plugin_dir_path( __FILE__ ) . 'src/metabox/presets-options.php'; 16 27 require_once plugin_dir_path( __FILE__ ) . 'src/triggers/triggers.php'; -
presets/trunk/readme.md
r2513575 r2516947 1 Presets is a WordPress plugin that allows you to fill your WordPress with previously defined demo/test data in just a few seconds allowing you to test it without the need to manually change the settings every time. 1 The Presets plugin allows you to fill your WordPress with previously defined settings in just a few seconds allowing you to test it without the need to manually change the settings every time. 2 3 Currently, you are able to change WordPress user meta details and define plugins to be activated/deactivate when a preset is triggered, but the goal will be to bring more WordPress and WooCommerce settings. We hope to make it easy in the long term to extend and bring more plugins settings. 2 4 3 5 This plugin hasn't been developed to be working on production sites. The goal with it is mostly to allow you to test plugins that require you to change the settings all the time. 4 5 Currently, you are only able to change WordPress user meta details, but the goal will be to bring more WordPress and WooCommerce settings. We hope to make it easy in the long term to extend and bring more plugins settings. -
presets/trunk/readme.txt
r2513575 r2516947 5 5 Tested up to: 5.7 6 6 Requires PHP: 7.0 7 Stable tag: 0. 1.07 Stable tag: 0.2.0 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 The Presets plugin allows you to fill your WordPress with demo data in just a few seconds allowing you to test it without the need to manually change the settings every time.11 The Presets plugin allows you to fill your WordPress with specific predefined settings in just a few seconds. 12 12 13 13 == Description == 14 14 15 The Presets plugin allows you to fill your WordPress with previously defined demo/test data in just a few seconds allowing you to test it without the need to manually change the settings every time. 15 The Presets plugin allows you to fill your WordPress with previously defined settings in just a few seconds allowing you to test it without the need to manually change the settings every time. 16 17 Currently, you are able to change WordPress user meta details and define plugins to be activated/deactivate when a preset is triggered, but the goal will be to bring more WordPress and WooCommerce settings. We hope to make it easy in the long term to extend and bring more plugins settings. 16 18 17 19 This plugin hasn't been developed to be working on production sites. The goal with it is mostly to allow you to test plugins that require you to change the settings all the time. 18 19 Currently, you are only able to change WordPress user meta details, but the goal will be to bring more WordPress and WooCommerce settings. We hope to make it easy in the long term to extend and bring more plugins settings.20 20 21 21 == Installation == … … 29 29 30 30 That plugin is not for production sites. it means that it won't probably make sense if you want to use it on your live site. It was created mostly with support teams and maybe even developers in mind that need to test things quickly and changing specific settings is required for that. 31 31 32 == Changelog == 33 34 = 0.2.0 = 35 Added the Plugins Module allowing you to activate/deactivate plugins when the preset is triggered. 32 36 33 37 = 0.1.0 = -
presets/trunk/src/actions/apply-presets.php
r2513575 r2516947 2 2 3 3 require_once plugin_dir_path( __FILE__ ) . 'core/user.php'; 4 require_once plugin_dir_path( __FILE__ ) . 'core/plugins.php'; 4 5 5 6 function get_presets_meta( $prefix, $field ) { 6 $selected_presets_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT ); 7 return get_post_meta( $selected_presets_id, 'presets_' . $prefix . $field, true ); 8 } 9 10 function presets_admin_notice__success() { ?> 11 <div class="notice notice-success is-dismissible"> 12 <p><?php _e( 'The settings were applied as expected! ', 'presets' ); ?></p> 13 </div> 14 <?php 7 $preset_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT ); 8 return get_post_meta( $preset_id, 'presets_' . $prefix . $field, true ); 15 9 } 16 10 … … 21 15 } 22 16 23 $ selected_presets_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT );17 $preset_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT ); 24 18 25 if ( get_post_type( $ selected_presets_id ) !== 'presets' ) {19 if ( get_post_type( $preset_id ) !== 'presets' ) { 26 20 return; 27 21 } 28 22 29 presets_core_user_apply_meta(); 30 31 add_action( 'admin_notices', 'presets_admin_notice__success' ); 23 /** 24 * presets_apply_meta hook. 25 * 26 * @hooked presets_core_user_apply_meta 27 * @hooked presets_core_plugins_apply_meta 28 */ 29 do_action( 'presets_apply_meta' ); 32 30 33 31 } 34 32 35 add_action( 'admin_head', 'apply_presets' ); 33 add_action( 'admin_init', 'apply_presets', 10 ); 34 35 /** 36 * Redirect after presets have been applied. 37 */ 38 function presets_apply_redirection() { 39 40 if ( ! isset( $_GET['presets-trigger'] ) || ! current_user_can( 'manage_options' ) ) { 41 return; 42 } 43 44 $preset_id = filter_var( $_GET['presets-trigger'], FILTER_SANITIZE_NUMBER_INT ); 45 46 $redirect_url = add_query_arg( 'presets-applied', $preset_id, remove_query_arg( 'presets-trigger', $_SERVER['REQUEST_URI'] ) ); 47 48 wp_safe_redirect( $redirect_url ); 49 exit; 50 51 } 52 53 add_action( 'admin_init', 'presets_apply_redirection', 20 ); 54 55 /** 56 * Display notice after action confirmation. 57 */ 58 function presets_admin_notice__success() { 59 60 if ( ! isset( $_GET['presets-applied'] ) || ! current_user_can( 'manage_options' ) ) { 61 return; 62 } 63 64 ?> 65 <div class="notice notice-success is-dismissible"> 66 <p><?php _e( 'The settings were applied as expected! ', 'presets' ); ?></p> 67 </div> 68 <?php 69 } 70 71 add_action( 'admin_notices', 'presets_admin_notice__success' ); -
presets/trunk/src/actions/core/user.php
r2513575 r2516947 27 27 28 28 } 29 30 add_action( 'presets_apply_meta', 'presets_core_user_apply_meta' ); -
presets/trunk/src/metabox/core/user.php
r2513575 r2516947 1 1 <?php 2 2 3 $prefix_meta = $prefix . 'core_user_'; 3 function presets_core_user_create_metabox() { 4 4 5 /** 6 * Initiate the metabox 7 */ 8 $cmb = new_cmb2_box( 9 array( 10 'id' => $prefix_meta . 'metabox', 11 'title' => __( '[Core] Current user', 'presets' ), 12 'object_types' => array( 'presets' ), // Post type 13 'context' => 'normal', 14 'priority' => 'high', 15 'show_names' => true, // Show field names on the left 16 // 'cmb_styles' => false, // false to disable the CMB stylesheet 17 // 'closed' => true, // Keep the metabox closed by default 18 ) 19 ); 5 $prefix_meta = 'presets_core_user_'; 20 6 21 $cmb->add_field( 22 array( 23 'name' => __( 'First Name', 'presets' ), 24 'id' => $prefix_meta . 'first_name', 25 'type' => 'text', 26 ) 27 ); 7 /** 8 * Initiate the metabox 9 */ 10 $cmb = new_cmb2_box( 11 array( 12 'id' => $prefix_meta . 'metabox', 13 'title' => __( '[Core] Current user', 'presets' ), 14 'object_types' => array( 'presets' ), // Post type 15 'context' => 'normal', 16 'priority' => 'high', 17 'show_names' => true, // Show field names on the left 18 // 'cmb_styles' => false, // false to disable the CMB stylesheet 19 // 'closed' => true, // Keep the metabox closed by default 20 ) 21 ); 28 22 29 $cmb->add_field(30 array(31 'name' => __( 'Last Name', 'presets' ),32 'id' => $prefix_meta . 'last_name',33 'type' => 'text',34 )35 );23 $cmb->add_field( 24 array( 25 'name' => __( 'First Name', 'presets' ), 26 'id' => $prefix_meta . 'first_name', 27 'type' => 'text', 28 ) 29 ); 36 30 37 $cmb->add_field(38 array(39 'name' => __( 'DisplayName', 'presets' ),40 'id' => $prefix_meta . 'display_name',41 'type' => 'text',42 )43 );31 $cmb->add_field( 32 array( 33 'name' => __( 'Last Name', 'presets' ), 34 'id' => $prefix_meta . 'last_name', 35 'type' => 'text', 36 ) 37 ); 44 38 45 $cmb->add_field(46 array(47 'name' => __( 'Website', 'presets' ),48 'id' => $prefix_meta . 'user_url',49 'type' => 'text_url',50 )51 );39 $cmb->add_field( 40 array( 41 'name' => __( 'Display Name', 'presets' ), 42 'id' => $prefix_meta . 'display_name', 43 'type' => 'text', 44 ) 45 ); 52 46 53 $cmb->add_field(54 array(55 'name' => __( 'Email', 'presets' ),56 'id' => $prefix_meta . 'user_email',57 'type' => 'text_email',58 )59 );47 $cmb->add_field( 48 array( 49 'name' => __( 'Website', 'presets' ), 50 'id' => $prefix_meta . 'user_url', 51 'type' => 'text_url', 52 ) 53 ); 60 54 61 $cmb->add_field( 62 array( 63 'name' => __( 'Bio', 'presets' ), 64 'id' => $prefix_meta . 'description', 65 'type' => 'textarea', 66 ) 67 ); 55 $cmb->add_field( 56 array( 57 'name' => __( 'Email', 'presets' ), 58 'id' => $prefix_meta . 'user_email', 59 'type' => 'text_email', 60 ) 61 ); 62 63 $cmb->add_field( 64 array( 65 'name' => __( 'Bio', 'presets' ), 66 'id' => $prefix_meta . 'description', 67 'type' => 'textarea', 68 ) 69 ); 70 71 } 72 73 add_action( 'presets_create_metabox', 'presets_core_user_create_metabox' ); -
presets/trunk/src/metabox/presets-options.php
r2513575 r2516947 2 2 3 3 /** 4 * Adding 'cmb2' vendor 4 * Adding 'cmb2' vendor. 5 5 */ 6 6 if ( file_exists( dirname( __FILE__ ) . '/../../vendors/cmb2/init.php' ) ) { … … 8 8 } 9 9 10 11 include_once plugin_dir_path( __FILE__ ) . 'core/user.php'; 12 include_once plugin_dir_path( __FILE__ ) . 'core/plugins.php'; 13 14 /** 15 * Create metabox. 16 */ 10 17 function presets_options() { 11 18 12 19 $prefix = 'presets_'; 13 20 14 include_once plugin_dir_path( __FILE__ ) . 'core/user.php'; 21 /** 22 * presets_create_metabox hook. 23 * 24 * @hooked presets_core_user_create_metabox 25 * @hooked presets_core_plugins_create_metabox 26 */ 27 do_action( 'presets_create_metabox' ); 15 28 16 29 } -
presets/trunk/src/triggers/triggers.php
r2513575 r2516947 2 2 3 3 include_once plugin_dir_path( __FILE__ ) . 'wp-admin-bar/trigger.php'; 4 5 function presets_get_ids() { 6 7 return get_posts( 8 array( 9 'fields' => 'ids', 10 'posts_per_page' => -1, 11 'post_type' => 'presets', 12 ) 13 ); 14 15 } 16 17 function presets_get_current_url( $id ) { 18 19 return add_query_arg( 'presets-trigger', $id, $_SERVER['REQUEST_URI'] ); 20 21 } -
presets/trunk/src/triggers/wp-admin-bar/trigger.php
r2513575 r2516947 6 6 return; 7 7 } 8 8 9 $admin_bar->add_menu( 9 10 array( … … 19 20 ); 20 21 21 $presets_ids = get_posts( 22 array( 23 'fields' => 'ids', 24 'posts_per_page' => -1, 25 'post_type' => 'presets', 26 ) 27 ); 28 29 foreach ( $presets_ids as $id ) { 22 foreach ( presets_get_ids() as $id ) { 30 23 31 24 $admin_bar->add_menu( … … 35 28 'group' => null, 36 29 'title' => get_the_title( $id ), // you can use img tag with image link. it will show the image icon Instead of the title. 37 'href' => admin_url( 'edit.php?post_type=presets&presets-trigger=' .$id ),30 'href' => presets_get_current_url( $id ), 38 31 'meta' => array( 39 32 'title' => get_the_title( $id ), // This title will show on hover. … … 46 39 } 47 40 48 add_action( 'admin_bar_menu', 'presets_admin_bar_item', 100 ); 41 add_action( 42 'admin_init', 43 function () { 44 add_action( 'admin_bar_menu', 'presets_admin_bar_item', 100 ); 45 } 46 );
Note: See TracChangeset
for help on using the changeset viewer.