/** * Administration Panel - Add-Meta-Tags Settings */ function amt_admin_init() { // Here we just add some dummy variables that contain the plugin name and // the description exactly as they appear in the plugin metadata, so that // they can be translated. $amt_plugin_name = __('Add Meta Tags', 'add-meta-tags'); $amt_plugin_description = __('Add basic meta tags and also Opengraph, Schema.org Microdata, Twitter Cards and Dublin Core metadata to optimize your web site for better SEO.', 'add-meta-tags'); // Perform automatic settings upgrade based on settings version. // Also creates initial default settings automatically. amt_plugin_upgrade(); // Register scripts and styles /* Register our script for the color picker. */ // wp_register_script( 'myPluginScript', plugins_url( 'script.js', AMT_PLUGIN_FILE ) ); /* Register our stylesheet. */ wp_register_style('amt_settings', plugins_url('css/amt-settings.css', AMT_PLUGIN_FILE)); }
/** * Import settings and data from standard input. * * ## OPTIONS * * <what> * : The type of data to be imported. Supported: settings|postdata|userdata|termdata * * ## EXAMPLES * * wp amt import settings < amt-settings.json * wp amt import postdata < amt-postdata.json * wp amt import userdata < amt-userdata.json * wp amt import termdata < amt-termdata.json * * @synopsis <settings|postdata|userdata|termdata> */ function import($args, $assoc_args) { list($what) = $args; if (!in_array($what, array('settings', 'postdata', 'userdata', 'termdata'))) { WP_CLI::error('Invalid argument: ' . $what . ' (valid: settings|postdata|userdata|termdata)'); } // Import AMT settings if ($what == 'settings') { $data = json_decode(file_get_contents('php://stdin'), true); // true converts to associative array //var_dump($data); if (empty($data) || !is_array($data)) { WP_CLI::error('No data found.'); } // Since all other options might come and go, we only check for the 'settings_version' key. if (!array_key_exists('settings_version', $data)) { WP_CLI::error('Invalid data: not option data'); } //var_dump( $options ); update_option("add_meta_tags_opts", $data); amt_plugin_upgrade(); WP_CLI::success('Add-Meta-Tags settings imported successfully.'); } elseif ($what == 'postdata') { $data = json_decode(file_get_contents('php://stdin')); if (empty($data) || !is_array($data) || empty($data[0])) { WP_CLI::error('No data found.'); } $amt_post_fields = amt_get_post_custom_field_names(); foreach ($data as $post_meta_info) { // Format: array( <id>, <field_name>, <field_value> ) if (!is_array($post_meta_info) || count($post_meta_info) != 3 || !in_array($post_meta_info[1], $amt_post_fields) || !is_numeric($post_meta_info[0])) { WP_CLI::error('Invalid data: not post custom field data'); } update_post_meta($post_meta_info[0], $post_meta_info[1], $post_meta_info[2]); } WP_CLI::success('Add-Meta-Tags post data was imported successfully.'); } elseif ($what == 'userdata') { $data = json_decode(file_get_contents('php://stdin')); if (empty($data) || !is_array($data) || empty($data[0])) { WP_CLI::error('No data found.'); } $amt_user_fields = amt_get_user_custom_field_names(); foreach ($data as $user_meta_info) { // Format: array( <id>, <field_name>, <field_value> ) if (!is_array($user_meta_info) || count($user_meta_info) != 3 || !in_array($user_meta_info[1], $amt_user_fields) || !is_numeric($user_meta_info[0])) { WP_CLI::error('Invalid data: not user contact infos'); } update_user_meta($user_meta_info[0], $user_meta_info[1], $user_meta_info[2]); } WP_CLI::success('Add-Meta-Tags user data was imported successfully.'); } elseif ($what == 'termdata') { $data = json_decode(file_get_contents('php://stdin')); if (empty($data) || !is_array($data) || empty($data[0])) { WP_CLI::error('No data found.'); } $amt_term_fields = amt_get_term_custom_field_names(); foreach ($data as $term_meta_info) { // Format: array( <id>, <field_name>, <field_value> ) if (!is_array($term_meta_info) || count($term_meta_info) != 3 || !in_array($term_meta_info[1], $amt_term_fields) || !is_numeric($term_meta_info[0])) { WP_CLI::error('Invalid data: not term contact infos'); } update_term_meta($term_meta_info[0], $term_meta_info[1], $term_meta_info[2]); } WP_CLI::success('Add-Meta-Tags term data was imported successfully.'); } }