. * */ /** * Prevent Direct Access * * @since 0.1 */ defined('ABSPATH') or die("Restricted access!"); /** * Plugin constants * * @since 2.0 */ 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__)); /** * Register text domain * * @since 2.0 */ function allmetatags_textdomain() { load_plugin_textdomain( 'all-meta-tags', 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', 'all-meta-tags' ) . ''; 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', 'all-meta-tags' ), __( 'All Meta Tags', 'all-meta-tags' ), 'manage_options', basename( __FILE__ ), 'allmetatags_render_submenu_page' ); } add_action( 'admin_menu', 'allmetatags_register_submenu_page' ); /** * Attach Settings Page * * @since 2.0 */ require_once( ALLMT_PATH . 'inc/settings_page.php' ); /** * Enqueue style sheet for setting's page * * @since 2.0 */ function allmetatags_enqueue_scripts($hook) { // Return if the page is not a settings page of this plugin if ( 'settings_page_all-meta-tags' != $hook ) { return; } wp_enqueue_style('styles', ALLMT_URL . 'inc/style.css'); } add_action('admin_enqueue_scripts', 'allmetatags_enqueue_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 1.0 */ function allmetatags_field($name, $label, $placeholder, $help=null, $link=null, $textarea=null) { // Declare variables $options = get_option( 'allmetatags_settings' ); if ( !empty($options[$name]) ) : $value = sanitize_text_field( $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 1.3 */ 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'] ); $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[] = ""; } // 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[] = ""; } // 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' ); ?>