SimpleSEO::$prefix . 'primary-meta-box',
'title' => __('Simple SEO Meta Tags', 'simple-seo-pack'),
'page' => array('page', 'post'),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => __('Keywords', 'simple-seo-pack'),
'desc' => __('Insert a list of desired keywords', 'simple-seo-pack'),
'id' => '_' . SimpleSEO::$prefix . 'meta_keywords',
'type' => 'text',
),
array(
'name' => __('Description', 'simple-seo-pack'),
'desc' => __('Insert a short description for this page or post', 'simple-seo-pack'),
'id' => '_' . SimpleSEO::$prefix . 'meta_description',
'type' => 'textarea',
),
array(
'name' => __('Use global settings (not recomended)', 'simple-seo-pack'),
'id' => '_' . SimpleSEO::$prefix . 'use_global_settings',
'type' => 'checkbox',
),
)
);
add_action('add_meta_boxes', array('SimpleSEO', 'add_metabox'));
add_action('save_post', array('SimpleSEO', 'save_postdata'));
// Add header meta tags
add_action('wp_head', array('SimpleSEO', 'print_keywords'));
add_action('wp_head', array('SimpleSEO', 'print_description'));
add_action('admin_enqueue_scripts', array('SimpleSEO', 'add_js_admin'));
// Adding support for qTranslate
if (function_exists('qtrans_init')) {
require_once dirname(__FILE__) . '/lib/qtranslate.php';
//wp_enqueue_script('sseo-qtrans', plugins_url('/js/sseo_qtrans.js', __FILE__), array('jquery'), '1.0', false);
add_filter('admin_footer', 'qtrans_sseo_modifyMetabox');
// Translation filters
add_filter('sseo_keywords', 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0);
add_filter('sseo_description', 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage', 0);
// Cleaning filters
add_filter('sseo_keywords', 'qtrans_sseo_cleanMeta');
add_filter('sseo_description', 'qtrans_sseo_cleanMeta');
} // end if
} // end function
/**
* Adds options menu
*/
function init_menu() {
// Add general options menu
add_options_page(__('Simple SEO', 'simple-seo-pack'), __('Simple SEO', 'simple-seo-pack'), 'manage_options', 'sseo-options', array('SimpleSEO', 'manage_options'));
} // end function
/**
* Manages the Simple SEO option page
*/
function manage_options() {
// Open page
echo '
';
echo "
" . __('Simple SEO Options', 'simple-seo-pack') . "
";
echo "
" . __("From here you can set the default values for the keywords and description meta tags. These values will be used for all the posts and pages which don't have their custom ones.", 'simple-seo-pack') . "
";
// Open form
echo '';
echo '
';
} // end function manage_options
/**
* Prints post or page keywords
*/
function print_keywords() {
global $post;
if (!is_object($post)) return;
if (is_archive()) return;
if ('on' == get_post_meta($post->ID, '_' . SimpleSEO::$prefix . 'use_global_settings', true)) {
if (!$keywords = get_option(SimpleSEO::$prefix . 'keywords')) {
return false;
} // end if
} else if (!$keywords = get_post_meta($post->ID, '_' . SimpleSEO::$prefix . 'meta_keywords', true)) {
return false;
} // end if
$keywords = apply_filters('sseo_keywords', $keywords);
if (!empty($keywords)) {
$html = '';
echo $html . "\n";
} // end if
} // end function print_keywords
/**
* Prints post or page description
*/
function print_description() {
global $post;
if (!is_object($post)) return;
if (is_archive()) return;
if ('on' == get_post_meta($post->ID, '_' . SimpleSEO::$prefix . 'use_global_settings', true)) {
if (!$description = get_option(SimpleSEO::$prefix . 'description')) {
return false;
} // end if
} else if (!$description = get_post_meta($post->ID, '_' . SimpleSEO::$prefix . 'meta_description', true)) {
return false;
} // end if
$description = apply_filters('sseo_description', $description);
if (!empty($description)) {
$html = '';
echo $html . "\n";
} // end if
} // end function print_keywords
/**
* Setup the metabox data for posts and pages
*
* @link http://codex.wordpress.org/Function_Reference/add_meta_box
*/
function add_metabox() {
$metabox = &SimpleSEO::$metabox;
foreach ($metabox['page'] as $post_type) {
add_meta_box($metabox['id'], $metabox['title'], array('SimpleSEO', 'show_metabox'), $post_type, $metabox['context'], $metabox['priority'], $metabox['fields']);
} // end foreach
} // end function
/**
* Displays the metabox content
*
* @param object $post The current post object passed by wordpress
* @param array $params The metabox data passed by wordpress, $params['args'] contains the custom arguments
*/
function show_metabox($post, $params) {
// Use nonce for verification
echo '';
$requiredFields = array();
echo '
';
foreach ($params['args'] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field['id'], true);
$field_id = str_replace(SimpleSEO::$prefix, '', $field['id']);
$field_id = $field['id'];
$required = '';
if (in_array($field['id'], $requiredFields)) {
$required = ' required';
} // end if
$beforeField = '';
echo '
';
switch ($field['type']) {
case 'text':
echo '', '
', $field['desc'];
break;
case 'small-text':
echo $beforeField, '', '
', $field['desc'];
break;
case 'textarea':
echo '', '
', $field['desc'];
break;
case 'select':
echo '';
break;
case 'radio':
foreach ($field['options'] as $option) {
echo '', $option['name'];
} // end foreach
break;
case 'checkbox':
echo '';
break;
break;
} // end switch
echo '
';
} // end foreach
echo '
';
} // end function
/**
* Check posted data and saves metabox data
*/
function save_postdata($post_id) {
// verify nonce
if (!wp_verify_nonce($_POST[SimpleSEO::$prefix . 'meta_box_nonce'], basename(__FILE__))) {
return $post_id;
} // end if
if ( wp_is_post_revision( $post_id ) ) {
return $post_id;
} // end if
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
} // end if
// check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
} // end if
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
} // end if
if ( !wp_is_post_revision( $post_id ) ) {
$sseo_fields = SimpleSEO::$metabox['fields'];
foreach ($sseo_fields as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = (isset($_POST[$field['id']])) ? $_POST[$field['id']]: null;
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
} // end if
} // end foreach
} // end if
} // end function
/**
* Safe add JS for admin panels
*/
function add_js_admin() {
// Add JS support for qTranslate
if (function_exists('qtrans_init')) {
wp_enqueue_script('sseo-qtrans', plugins_url('/js/sseo_qtrans.js', __FILE__), array('jquery'), '1.0', false);
} // end if
} // end function
} // end class
/// MAIN----------------------------------------------------------------------
add_action('plugins_loaded', array('SimpleSEO', 'init'));
?>