Skip to content

Commit

Permalink
- fixed meta description
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels Garve committed Dec 28, 2017
1 parent 7eb020a commit f3e18e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.idea
66 changes: 23 additions & 43 deletions plugin.php
Expand Up @@ -33,8 +33,6 @@ class WPAPIYoastMeta {

function __construct() {
add_action( 'rest_api_init', array( $this, 'add_yoast_data' ) );

add_filter('worona_get_site_info', array($this,'get_site_info'));
}

function add_yoast_data() {
Expand Down Expand Up @@ -116,46 +114,37 @@ function wp_api_update_yoast( $value, $data, $field_name ) {
return $this->wp_api_encode_yoast( $data->ID, null, null );
}

function get_title_home_wpseo() {
$wpseo_frontend = WPAPI_WPSEO_Frontend::get_instance();

return $wpseo_frontend->get_title_from_options( 'title-home-wpseo' );
}

function get_metadesc_home_wpseo() {
$wpseo_frontend = WPAPI_WPSEO_Frontend::get_instance();
$wpseo_replace_vars = new WPAPI_WPSEO_Replace_Vars();
function wp_api_encode_yoast($p, $field_name, $request) {
global $post;

//Generate metadesc-home-wpseo
$metadesc = $wpseo_frontend->options['metadesc-home-wpseo'];
$post_data = array();
$omit = array();
$wpseo_frontend = WPAPI_WPSEO_Frontend::get_instance();
$wpseo_replace_vars = new WPAPI_WPSEO_Replace_Vars();

if ( empty( $metadesc ) ) {
$metadesc = get_bloginfo( 'description' );
}
query_posts(array(
'p' => $p['id'], // ID of a page, post, or custom type
'post_type' => 'any'
));

return $wpseo_replace_vars->replace( $metadesc, $post_data, $omit );
}
the_post();

function wp_api_encode_yoast( $p, $field_name, $request ) {
$wpseo_frontend = WPAPI_WPSEO_Frontend::get_instance();
$metadesc = get_post_meta($p['id'], '_yoast_wpseo_metadesc', true);

$args = array(
'p' => $p['id'], // ID of a page, post, or custom type
'post_type' => 'any'
);
if (empty($metadesc)) {
$metadesc = $wpseo_frontend->metadesc(false);
} else {
$metadesc = $wpseo_replace_vars->replace($metadesc, $post);
}

$GLOBALS['wp_query'] = new WP_Query( $args );
$yoastMeta = array(
'yoast_wpseo_title' => $wpseo_frontend->get_content_title(),
'yoast_wpseo_metadesc' => $metadesc,
'yoast_wpseo_canonical' => $wpseo_frontend->canonical(false),
);

$yoastMeta = array(
'yoast_wpseo_title' => $wpseo_frontend->get_content_title(),
'yoast_wpseo_metadesc' => $wpseo_frontend->metadesc(false),
'yoast_wpseo_canonical' => $wpseo_frontend->canonical(false),
);
wp_reset_query();

return (array) $yoastMeta;
}
return (array)$yoastMeta;
}

function wp_api_encode_taxonomy (){
$wpseo_frontend = WPAPI_WPSEO_Frontend::get_instance();
Expand Down Expand Up @@ -185,15 +174,6 @@ function wp_api_encode_yoast_tag($tag){

return $this->wp_api_encode_taxonomy();
}

function get_site_info($site_info) {

$site_info['homepage_title'] = $this->get_title_home_wpseo();
$site_info['homepage_metadesc'] = $this->get_metadesc_home_wpseo();

return $site_info;
}

}

function WPAPIYoast_init() {
Expand Down

0 comments on commit f3e18e5

Please sign in to comment.