build_data(); } /** * Builds all the required data for the context object. */ private function build_data() { // Page level variables. $front = WPSEO_Frontend::get_instance(); $this->canonical = $front->canonical( false, false, true ); $this->title = $front->title( '' ); $this->description = $front->metadesc( false ); $this->id = get_queried_object_id(); // Site level variables. $this->site_name = $this->set_site_name(); $this->site_description = get_bloginfo( 'description' ); $this->site_url = trailingslashit( WPSEO_Utils::home_url() ); $this->set_breadcrumbs_variables(); $this->set_site_represents_variables(); $this->set_site_represents_reference(); } /** * Retrieves the site's name from settings. * * @return string */ private function set_site_name() { if ( WPSEO_Options::get( 'website_name', '' ) !== '' ) { return WPSEO_Options::get( 'website_name' ); } return get_bloginfo( 'name' ); } /** * Sets our site represents reference for easy use. */ private function set_site_represents_reference() { $this->site_represents_reference = false; if ( $this->site_represents === 'person' ) { $this->site_represents_reference = [ '@id' => WPSEO_Schema_Utils::get_user_schema_id( $this->site_user_id, $this ) ]; } if ( $this->site_represents === 'company' ) { $this->site_represents_reference = [ '@id' => $this->site_url . WPSEO_Schema_IDs::ORGANIZATION_HASH ]; } } /** * Determines what our site represents, and grabs their values. */ private function set_site_represents_variables() { $this->site_represents = WPSEO_Options::get( 'company_or_person', false ); switch ( $this->site_represents ) { case 'company': $company_name = WPSEO_Options::get( 'company_name' ); /** * Filter: 'wpseo_schema_company_name' - Allows filtering company name * * @api string $company_name. */ $this->company_name = apply_filters( 'wpseo_schema_company_name', $company_name ); // Do not use a non-named company. if ( empty( $this->company_name ) ) { $this->site_represents = false; break; } $company_logo_id = WPSEO_Image_Utils::get_attachment_id_from_settings( 'company_logo' ); /** * Filter: 'wpseo_schema_company_logo_id' - Allows filtering company logo id * * @api integer $company_logo_id. */ $this->company_logo_id = apply_filters( 'wpseo_schema_company_logo_id', $company_logo_id ); /* * Do not use a company without a logo. * This is not a false check due to how `get_attachment_id_from_settings` works. */ if ( $this->company_logo_id < 1 ) { $this->site_represents = false; } break; case 'person': $this->site_user_id = WPSEO_Options::get( 'company_or_person_user_id', false ); // Do not use a non-existing user. if ( $this->site_user_id !== false && get_user_by( 'id', $this->site_user_id ) === false ) { $this->site_represents = false; } break; } } /** * Determines whether the site uses Yoast SEO breadcrumbs. */ private function set_breadcrumbs_variables() { $this->breadcrumbs_enabled = current_theme_supports( 'yoast-seo-breadcrumbs' ); if ( ! $this->breadcrumbs_enabled ) { $this->breadcrumbs_enabled = WPSEO_Options::get( 'breadcrumbs-enable', false ); } } }