reset_defaults();
wp_redirect( admin_url( 'admin.php?page=wpseo_dashboard' ) );
}
global $wpseo_admin;
if ( $wpseo_admin->grant_access() ) {
add_action( 'admin_print_scripts', array( $this, 'config_page_scripts' ) );
add_action( 'admin_print_styles', array( $this, 'config_page_styles' ) );
}
}
/**
* Resets the site to the default WordPress SEO settings and runs a title test to check whether force rewrite needs to be on.
*/
function reset_defaults() {
foreach ( get_wpseo_options_arr() as $opt ) {
delete_option( $opt );
}
wpseo_defaults();
wpseo_title_test();
}
/**
* Generates the sidebar for admin pages.
*/
function admin_sidebar() {
?>
' . __( 'Want to help make this plugin even better? All donations are used to improve this plugin, so donate $10, $20 or $50 now!', 'wordpress-seo' ) . '
';
settings_fields( $option );
$this->currentoption = $optionshort;
}
}
/**
* Generates the footer for admin pages
*
* @param bool $submit Whether or not a submit button should be shown.
*/
function admin_footer( $submit = true ) {
if ( $submit ) {
?>
"/>
admin_sidebar(); ?>
get_results( "SELECT * FROM $wpdb->postmeta WHERE meta_key = '$old_metakey'" );
foreach ( $oldies as $old ) {
// Prevent inserting new meta values for posts that already have a value for that new meta key
$check = $wpdb->get_var( "SELECT count(*) FROM $wpdb->postmeta WHERE meta_key = '$new_metakey' AND post_id = " . $old->post_id );
if ( $check == 0 )
$wpdb->query( "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES (" . $old->post_id . ",'" . $new_metakey . "','" . addslashes( $old->meta_value ) . "')" );
}
if ( $replace ) {
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '$old_metakey'" );
}
}
/**
* Deletes all post meta values with a given meta key from the database
*
* @param string $metakey Key to delete all meta values for.
*/
function delete_meta( $metakey ) {
global $wpdb;
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '$metakey'" );
}
/**
* Exports the current site's WP SEO settings.
*
* @param bool $include_taxonomy Whether to include the taxonomy metadata the plugin creates.
* @return bool|string $return False when failed, the URL to the export file when succeeded.
*/
function export_settings( $include_taxonomy ) {
$content = "; " . __( "This is a settings export file for the WordPress SEO plugin by Yoast.com", 'wordpress-seo' ) . " - http://yoast.com/wordpress/seo/ \r\n";
$optarr = get_wpseo_options_arr();
foreach ( $optarr as $optgroup ) {
$content .= "\n" . '[' . $optgroup . ']' . "\n";
$options = get_option( $optgroup );
if ( !is_array( $options ) )
continue;
foreach ( $options as $key => $elem ) {
if ( is_array( $elem ) ) {
for ( $i = 0; $i < count( $elem ); $i++ ) {
$content .= $key . "[] = \"" . $elem[$i] . "\"\n";
}
} else if ( $elem == "" )
$content .= $key . " = \n";
else
$content .= $key . " = \"" . $elem . "\"\n";
}
}
if ( $include_taxonomy ) {
$content .= "\r\n\r\n[wpseo_taxonomy_meta]\r\n";
$content .= "wpseo_taxonomy_meta = \"" . urlencode( json_encode( get_option( 'wpseo_taxonomy_meta' ) ) ) . "\"";
}
$dir = wp_upload_dir();
if ( !$handle = fopen( $dir['path'] . '/settings.ini', 'w' ) )
die();
if ( !fwrite( $handle, $content ) )
die();
fclose( $handle );
require_once ( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
chdir( $dir['path'] );
$zip = new PclZip( './settings.zip' );
if ( $zip->create( './settings.ini' ) == 0 )
return false;
return $dir['url'] . '/settings.zip';
}
/**
* Loads the required styles for the config page.
*/
function config_page_styles() {
global $pagenow;
if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) && in_array( $_GET['page'], $this->adminpages ) ) {
wp_enqueue_style( 'dashboard' );
wp_enqueue_style( 'thickbox' );
wp_enqueue_style( 'global' );
wp_enqueue_style( 'wp-admin' );
wp_enqueue_style( 'yoast-admin-css', WPSEO_URL . 'css/yst_plugin_tools.css', WPSEO_VERSION );
}
}
/**
* Loads the required scripts for the config page.
*/
function config_page_scripts() {
global $pagenow;
if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) && in_array( $_GET['page'], $this->adminpages ) ) {
wp_enqueue_script( 'wpseo-admin-script', WPSEO_URL . 'js/wp-seo-admin.js', array( 'jquery' ), WPSEO_VERSION, true );
wp_enqueue_script( 'postbox' );
wp_enqueue_script( 'dashboard' );
wp_enqueue_script( 'thickbox' );
}
}
/**
* Retrieve options based on the option or the class currentoption.
*
* @since 1.2.4
*
* @param string $option The option to retrieve.
* @return array
*/
function get_option( $option ) {
if ( function_exists( 'is_network_admin' ) && is_network_admin() )
return get_site_option( $option );
else
return get_option( $option );
}
/**
* Create a Checkbox input field.
*
* @param string $var The variable within the option to create the checkbox for.
* @param string $label The label to show for the variable.
* @param bool $label_left Whether the label should be left (true) or right (false).
* @param string $option The option the variable belongs to.
* @return string
*/
function checkbox( $var, $label, $label_left = false, $option = '' ) {
if ( empty( $option ) )
$option = $this->currentoption;
$options = $this->get_option( $option );
if ( !isset( $options[$var] ) )
$options[$var] = false;
if ( $label_left !== false ) {
if ( !empty( $label_left ) )
$label_left .= ':';
$output_label = '';
$class = 'checkbox';
} else {
$output_label = '';
$class = 'checkbox double';
}
$output_input = "';
if ( $label_left !== false ) {
$output = $output_label . $output_input . '';
} else {
$output = $output_input . $output_label;
}
return $output . ' ';
}
/**
* Create a Text input field.
*
* @param string $var The variable within the option to create the text input field for.
* @param string $label The label to show for the variable.
* @param string $option The option the variable belongs to.
* @return string
*/
function textinput( $var, $label, $option = '' ) {
if ( empty( $option ) )
$option = $this->currentoption;
$options = $this->get_option( $option );
$val = '';
if ( isset( $options[$var] ) )
$val = esc_attr( $options[$var] );
return '' . ' ';
}
/**
* Create a textarea.
*
* @param string $var The variable within the option to create the textarea for.
* @param string $label The label to show for the variable.
* @param string $option The option the variable belongs to.
* @param string $class The CSS class to assign to the textarea.
* @return string
*/
function textarea( $var, $label, $option = '', $class = '' ) {
if ( empty( $option ) )
$option = $this->currentoption;
$options = $this->get_option( $option );
$val = '';
if ( isset( $options[$var] ) )
$val = esc_attr( $options[$var] );
return '' . ' ';
}
/**
* Create a hidden input field.
*
* @param string $var The variable within the option to create the hidden input for.
* @param string $option The option the variable belongs to.
* @return string
*/
function hidden( $var, $option = '' ) {
if ( empty( $option ) )
$option = $this->currentoption;
$options = $this->get_option( $option );
$val = '';
if ( isset( $options[$var] ) )
$val = esc_attr( $options[$var] );
return '';
}
/**
* Create a Select Box.
*
* @param string $var The variable within the option to create the select for.
* @param string $label The label to show for the variable.
* @param string $values The select options to choose from.
* @param string $option The option the variable belongs to.
* @return string
*/
function select( $var, $label, $values, $option = '' ) {
if ( empty( $option ) )
$option = $this->currentoption;
$options = $this->get_option( $option );
$output = '';
$output .= '';
return $output . ' ';
}
/**
* Create a File upload field.
*
* @param string $var The variable within the option to create the file upload field for.
* @param string $label The label to show for the variable.
* @param string $option The option the variable belongs to.
* @return string
*/
function file_upload( $var, $label, $option = '' ) {
if ( empty( $option ) )
$option = $this->currentoption;
$options = $this->get_option( $option );
$val = '';
if ( isset( $options[$var] ) && strtolower( gettype( $options[$var] ) ) == 'array' ) {
$val = $options[$var]['url'];
}
$output = '';
$output .= '';
// Need to save separate array items in hidden inputs, because empty file inputs type will be deleted by settings API.
if ( !empty( $options[$var] ) ) {
$output .= '';
$output .= '';
$output .= '';
}
$output .= ' ';
return $output;
}
/**
* Create a Radio input field.
*
* @param string $var The variable within the option to create the file upload field for.
* @param string $values The radio options to choose from.
* @param string $label The label to show for the variable.
* @param string $option The option the variable belongs to.
* @return string
*/
function radio( $var, $values, $label, $option = '' ) {
if ( empty( $option ) )
$option = $this->currentoption;
$options = $this->get_option( $option );
if ( !isset( $options[$var] ) )
$options[$var] = false;
$output = ' ';
foreach ( $values as $key => $value ) {
$output .= ' ';
}
$output .= ' ';
return $output;
}
/**
* Create a potbox widget.
*
* @param string $id ID of the postbox.
* @param string $title Title of the postbox.
* @param string $content Content of the postbox.
*/
function postbox( $id, $title, $content ) {
?>
';
$this->postbox( 'yoastlatest', __( 'Latest news from Yoast', 'wordpress-seo' ), $content );
}
} // end class WPSEO_Admin
global $wpseo_admin_pages;
$wpseo_admin_pages = new WPSEO_Admin_Pages();