. * */ /** * Prevent Direct Access * * @since 0.1 */ defined('ABSPATH') or die("Restricted access!"); /** * Define global constants * * @since 3.7 */ defined('ALLMT_DIR') or define('ALLMT_DIR', dirname(plugin_basename(__FILE__))); defined('ALLMT_BASE') or define('ALLMT_BASE', plugin_basename(__FILE__)); defined('ALLMT_URL') or define('ALLMT_URL', plugin_dir_url(__FILE__)); defined('ALLMT_PATH') or define('ALLMT_PATH', plugin_dir_path(__FILE__)); defined('ALLMT_TEXT') or define('ALLMT_TEXT', 'all-meta-tags'); defined('ALLMT_VERSION') or define('ALLMT_VERSION', '3.7'); /** * Register text domain * * @since 2.0 */ function allmetatags_textdomain() { load_plugin_textdomain( ALLMT_TEXT, false, ALLMT_DIR . '/languages/' ); } add_action( 'init', 'allmetatags_textdomain' ); /** * Print direct link to All Meta Tags admin page * * Fetches array of links generated by WP Plugin admin page ( Deactivate | Edit ) * and inserts a link to the All Meta Tags admin page * * @since 2.0 * @param array $links Array of links generated by WP in Plugin Admin page. * @return array Array of links to be output on Plugin Admin page. */ function allmetatags_settings_link( $links ) { $settings_page = '' . __( 'Settings', ALLMT_TEXT ) . ''; array_unshift( $links, $settings_page ); return $links; } add_filter( 'plugin_action_links_'.ALLMT_BASE, 'allmetatags_settings_link' ); /** * Register "All Meta Tags" submenu in "Settings" Admin Menu * * @since 2.0 */ function allmetatags_register_submenu_page() { add_options_page( __( 'All Meta Tags', ALLMT_TEXT ), __( 'All Meta Tags', ALLMT_TEXT ), 'manage_options', basename( __FILE__ ), 'allmetatags_render_submenu_page' ); } add_action( 'admin_menu', 'allmetatags_register_submenu_page' ); /** * Attach Settings Page * * @since 3.0 */ require_once( ALLMT_PATH . 'inc/php/settings_page.php' ); /** * Load scripts and style sheet for settings page * * @since 3.1 */ function allmetatags_load_scripts($hook) { // Return if the page is not a settings page of this plugin if ( 'settings_page_all-meta-tags' != $hook ) { return; } // Style sheet wp_enqueue_style( 'allmetatags-admin-css', ALLMT_URL . 'inc/css/admin.css' ); // JavaScript wp_enqueue_script( 'allmetatags-admin-js', ALLMT_URL . 'inc/js/admin.js', array(), false, true ); } add_action( 'admin_enqueue_scripts', 'allmetatags_load_scripts' ); /** * Register settings * * @since 0.1 */ function allmetatags_register_settings() { register_setting( 'allmetatags_settings_group', 'allmetatags_settings' ); } add_action( 'admin_init', 'allmetatags_register_settings' ); /** * Render fields * * @since 3.2 */ function allmetatags_field($name, $label, $placeholder, $help=null, $link=null, $textarea=null) { // Declare variables $options = get_option( 'allmetatags_settings' ); if ( !empty($options[$name]) ) : $value = esc_attr( $options[$name] ); else : $value = ""; endif; // Generate the table if ( !empty($link) ) : $link_out = "$label"; else : $link_out = "$label"; endif; if ( !empty($textarea) ) : $field_out = ""; else : $field_out = ""; endif; if ( !empty($help) ) : $help_out = " $help "; else : $help_out = ""; endif; // Put table to the variable $out = " $link_out $field_out $help_out"; // Print the generated table echo $out; } /** * Generate the Meta Tags * * @since 3.8 */ function allmetatags_add_meta_tags() { // Read options from BD, sanitiz data and declare variables $options = get_option( 'allmetatags_settings' ); $google = esc_textarea( $options['google'] ); $bing = esc_textarea( $options['bing'] ); $yandex = esc_textarea( $options['yandex'] ); $alexa = esc_textarea( $options['alexa'] ); $pinterest = esc_textarea( $options['pinterest'] ); $google_author = esc_textarea( $options['google_author'] ); $facebook = esc_textarea( $options['facebook'] ); $twitter = esc_textarea( $options['twitter'] ); $norton = esc_textarea( $options['norton'] ); $wot = esc_textarea( $options['wot'] ); $specificfeeds = esc_textarea( $options['specificfeeds'] ); $custom_meta = $options['custom_meta']; $home_description = esc_textarea( $options['home_description'] ); $home_keywords = esc_textarea( $options['home_keywords'] ); $blog_description = esc_textarea( $options['blog_description'] ); $blog_keywords = esc_textarea( $options['blog_keywords'] ); $author = esc_textarea( $options['author'] ); $designer = esc_textarea( $options['designer'] ); $contact = esc_textarea( $options['contact'] ); $copyright = esc_textarea( $options['copyright'] ); $keywords = esc_textarea( $options['keywords'] ); $metatags_arr[] = ""; // Web Master Tools if (!empty($google)) { $metatags_arr[] = ""; } if (!empty($yandex)) { $metatags_arr[] = ""; } if (!empty($bing)) { $metatags_arr[] = ""; } // Website Verification Services if (!empty($pinterest)) { $metatags_arr[] = ""; } if (!empty($google_author)) { $metatags_arr[] = ""; } if (!empty($facebook)) { $metatags_arr[] = ""; } if (!empty($twitter)) { $metatags_arr[] = ""; $metatags_arr[] = ""; } if (!empty($alexa)) { $metatags_arr[] = ""; } if (!empty($norton)) { $metatags_arr[] = ""; } if (!empty($wot)) { $metatags_arr[] = ""; } if (!empty($specificfeeds)) { $metatags_arr[] = ""; } if (!empty($custom_meta)) { $metatags_arr[] = $custom_meta; } // Meta Tags for specific pages if ( is_front_page() && is_home() ) { // Default Home Page if (!empty($home_description)) { $metatags_arr[] = ""; } if (!empty($home_keywords)) { $metatags_arr[] = ""; } } elseif ( is_front_page() ) { // Static Home Page if (!empty($home_description)) { $metatags_arr[] = ""; } if (!empty($home_keywords)) { $metatags_arr[] = ""; } } elseif ( is_home() ) { // Blog Page if (!empty($home_description)) { $metatags_arr[] = ""; } if (!empty($home_keywords)) { $metatags_arr[] = ""; } } // Meta Tags for all website if (!empty($author)) { $metatags_arr[] = ""; } if (!empty($designer)) { $metatags_arr[] = ""; } if (!empty($contact)) { $metatags_arr[] = ""; } if (!empty($copyright)) { $metatags_arr[] = ""; } if (!empty($keywords)) { $metatags_arr[] = ""; } // WooCommerce & Google Shopping (Merchant Center) if ( class_exists( 'WooCommerce' ) ) { if ( is_product() ) { $name = get_the_title(); $description = get_the_excerpt(); $image = simplexml_load_string(get_the_post_thumbnail()); if ( !empty($image) ) { $imagesrc = $image->attributes()->src; } else { $imagesrc = ""; } $price = get_post_meta( get_the_ID(), '_price', true); $currency = get_woocommerce_currency(); $google_shopping = "
"; $metatags_arr[] = $google_shopping; } } // Add comment if ( count( $metatags_arr ) > 0 ) { array_unshift( $metatags_arr, "" ); array_push( $metatags_arr, "" ); } // Return the content of array return $metatags_arr; } /** * Include the Meta Tags in head area * * @since 1.0 */ function allmetatags_add_metadata_head() { echo PHP_EOL, implode(PHP_EOL, allmetatags_add_meta_tags()), PHP_EOL, PHP_EOL; } add_action( 'wp_head', 'allmetatags_add_metadata_head', 0 ); /** * Delete options on uninstall * * @since 0.1 */ function allmetatags_uninstall() { delete_option( 'allmetatags_settings' ); } register_uninstall_hook( __FILE__, 'allmetatags_uninstall' ); ?>