| @@ -155,8 +155,64 @@ | ||
| 155 | 155 | echo new Alert_Presenter( $content ); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
| 159 | + * Translates text strings for use in the meta box. | |
| 160 | + * | |
| 161 | + * IMPORTANT: if you want to add a new string (option) somewhere, make sure you add that array key to | |
| 162 | + * the main meta box definition array in the class WPSEO_Meta() as well!!!! | |
| 163 | + * | |
| 164 | + * @deprecated 23.5 | |
| 165 | + * @codeCoverageIgnore | |
| 166 | + * | |
| 167 | + * @return void | |
| 168 | + */ | |
| 169 | + public static function translate_meta_boxes() { | |
| 170 | + _deprecated_function( __METHOD__, 'Yoast SEO 23.5' ); | |
| 171 | + | |
| 172 | + WPSEO_Meta::$meta_fields['general']['title']['title'] = __( 'SEO title', 'wordpress-seo' ); | |
| 173 | + WPSEO_Meta::$meta_fields['general']['metadesc']['title'] = __( 'Meta description', 'wordpress-seo' ); | |
| 174 | + | |
| 175 | + /* translators: %s expands to the post type name. */ | |
| 176 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['title'] = __( 'Allow search engines to show this %s in search results?', 'wordpress-seo' ); | |
| 177 | + if ( (string) get_option( 'blog_public' ) === '0' ) { | |
| 178 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['description'] = '<span class="error-message">' . __( 'Warning: even though you can set the meta robots setting here, the entire site is set to noindex in the sitewide privacy settings, so these settings won\'t have an effect.', 'wordpress-seo' ) . '</span>'; | |
| 179 | + } | |
| 180 | + /* translators: %1$s expands to Yes or No, %2$s expands to the post type name.*/ | |
| 181 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['0'] = __( 'Default for %2$s, currently: %1$s', 'wordpress-seo' ); | |
| 182 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['2'] = __( 'Yes', 'wordpress-seo' ); | |
| 183 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-noindex']['options']['1'] = __( 'No', 'wordpress-seo' ); | |
| 184 | + | |
| 185 | + /* translators: %1$s expands to the post type name.*/ | |
| 186 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['title'] = __( 'Should search engines follow links on this %1$s?', 'wordpress-seo' ); | |
| 187 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['options']['0'] = __( 'Yes', 'wordpress-seo' ); | |
| 188 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-nofollow']['options']['1'] = __( 'No', 'wordpress-seo' ); | |
| 189 | + | |
| 190 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['title'] = __( 'Meta robots advanced', 'wordpress-seo' ); | |
| 191 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['description'] = __( 'If you want to apply advanced <code>meta</code> robots settings for this page, please define them in the following field.', 'wordpress-seo' ); | |
| 192 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['noimageindex'] = __( 'No Image Index', 'wordpress-seo' ); | |
| 193 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['noarchive'] = __( 'No Archive', 'wordpress-seo' ); | |
| 194 | + WPSEO_Meta::$meta_fields['advanced']['meta-robots-adv']['options']['nosnippet'] = __( 'No Snippet', 'wordpress-seo' ); | |
| 195 | + | |
| 196 | + WPSEO_Meta::$meta_fields['advanced']['bctitle']['title'] = __( 'Breadcrumbs Title', 'wordpress-seo' ); | |
| 197 | + WPSEO_Meta::$meta_fields['advanced']['bctitle']['description'] = __( 'Title to use for this page in breadcrumb paths', 'wordpress-seo' ); | |
| 198 | + | |
| 199 | + WPSEO_Meta::$meta_fields['advanced']['canonical']['title'] = __( 'Canonical URL', 'wordpress-seo' ); | |
| 200 | + | |
| 201 | + WPSEO_Meta::$meta_fields['advanced']['canonical']['description'] = sprintf( | |
| 202 | + /* translators: 1: link open tag; 2: link close tag. */ | |
| 203 | + __( 'The canonical URL that this page should point to. Leave empty to default to permalink. %1$sCross domain canonical%2$s supported too.', 'wordpress-seo' ), | |
| 204 | + '<a href="https://googlewebmastercentral.blogspot.com/2009/12/handling-legitimate-cross-domain.html" target="_blank" rel="noopener">', | |
| 205 | + WPSEO_Admin_Utils::get_new_tab_message() . '</a>', | |
| 206 | + ); | |
| 207 | + | |
| 208 | + WPSEO_Meta::$meta_fields['advanced']['redirect']['title'] = __( '301 Redirect', 'wordpress-seo' ); | |
| 209 | + WPSEO_Meta::$meta_fields['advanced']['redirect']['description'] = __( 'The URL that this page should redirect to.', 'wordpress-seo' ); | |
| 210 | + | |
| 211 | + do_action_deprecated( 'wpseo_tab_translate', [], 'Yoast SEO 23.5', '', 'WPSEO_Metabox::translate_meta_boxes is deprecated.' ); | |
| 212 | + } | |
| 213 | + | |
| 214 | + /** | |
| 159 | 215 | * Determines whether the metabox should be shown for the passed identifier. |
| 160 | 216 | * |
| 161 | 217 | * By default the check is done for post types, but can also be used for taxonomies. |
| 162 | 218 | * |
| @@ -448,8 +504,185 @@ | ||
| 448 | 504 | } |
| 449 | 505 | } |
| 450 | 506 | |
| 451 | 507 | return $tabs; |
| 508 | + } | |
| 509 | + | |
| 510 | + /** | |
| 511 | + * Adds a line in the meta box. | |
| 512 | + * | |
| 513 | + * @deprecated 23.5 | |
| 514 | + * @codeCoverageIgnore | |
| 515 | + * | |
| 516 | + * @param string[] $meta_field_def Contains the vars based on which output is generated. | |
| 517 | + * @param string $key Internal key (without prefix). | |
| 518 | + * | |
| 519 | + * @return string | |
| 520 | + */ | |
| 521 | + public function do_meta_box( $meta_field_def, $key = '' ) { | |
| 522 | + _deprecated_function( __METHOD__, 'Yoast SEO 23.5' ); | |
| 523 | + | |
| 524 | + $content = ''; | |
| 525 | + $esc_form_key = esc_attr( WPSEO_Meta::$form_prefix . $key ); | |
| 526 | + $meta_value = WPSEO_Meta::get_value( $key, $this->get_metabox_post()->ID ); | |
| 527 | + | |
| 528 | + $class = ''; | |
| 529 | + if ( isset( $meta_field_def['class'] ) && $meta_field_def['class'] !== '' ) { | |
| 530 | + $class = ' ' . $meta_field_def['class']; | |
| 531 | + } | |
| 532 | + | |
| 533 | + $placeholder = ''; | |
| 534 | + if ( isset( $meta_field_def['placeholder'] ) && $meta_field_def['placeholder'] !== '' ) { | |
| 535 | + $placeholder = $meta_field_def['placeholder']; | |
| 536 | + } | |
| 537 | + | |
| 538 | + $aria_describedby = ''; | |
| 539 | + $description = ''; | |
| 540 | + if ( isset( $meta_field_def['description'] ) ) { | |
| 541 | + $aria_describedby = ' aria-describedby="' . $esc_form_key . '-desc"'; | |
| 542 | + $description = '<p id="' . $esc_form_key . '-desc" class="yoast-metabox__description">' . $meta_field_def['description'] . '</p>'; | |
| 543 | + } | |
| 544 | + | |
| 545 | + // Add a hide_on_pages option that returns nothing when the field is rendered on a page. | |
| 546 | + if ( isset( $meta_field_def['hide_on_pages'] ) && $meta_field_def['hide_on_pages'] && get_post_type() === 'page' ) { | |
| 547 | + return ''; | |
| 548 | + } | |
| 549 | + | |
| 550 | + switch ( $meta_field_def['type'] ) { | |
| 551 | + case 'text': | |
| 552 | + $ac = ''; | |
| 553 | + if ( isset( $meta_field_def['autocomplete'] ) && $meta_field_def['autocomplete'] === false ) { | |
| 554 | + $ac = 'autocomplete="off" '; | |
| 555 | + } | |
| 556 | + if ( $placeholder !== '' ) { | |
| 557 | + $placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"'; | |
| 558 | + } | |
| 559 | + $content .= '<input type="text"' . $placeholder . ' id="' . $esc_form_key . '" ' . $ac . 'name="' . $esc_form_key . '" value="' . esc_attr( $meta_value ) . '" class="large-text' . $class . '"' . $aria_describedby . '/>'; | |
| 560 | + break; | |
| 561 | + | |
| 562 | + case 'url': | |
| 563 | + if ( $placeholder !== '' ) { | |
| 564 | + $placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"'; | |
| 565 | + } | |
| 566 | + $content .= '<input type="url"' . $placeholder . ' id="' . $esc_form_key . '" name="' . $esc_form_key . '" value="' . esc_attr( urldecode( $meta_value ) ) . '" class="large-text' . $class . '"' . $aria_describedby . '/>'; | |
| 567 | + break; | |
| 568 | + | |
| 569 | + case 'textarea': | |
| 570 | + $rows = 3; | |
| 571 | + if ( isset( $meta_field_def['rows'] ) && $meta_field_def['rows'] > 0 ) { | |
| 572 | + $rows = $meta_field_def['rows']; | |
| 573 | + } | |
| 574 | + $content .= '<textarea class="large-text' . $class . '" rows="' . esc_attr( $rows ) . '" id="' . $esc_form_key . '" name="' . $esc_form_key . '"' . $aria_describedby . '>' . esc_textarea( $meta_value ) . '</textarea>'; | |
| 575 | + break; | |
| 576 | + | |
| 577 | + case 'hidden': | |
| 578 | + $default = ''; | |
| 579 | + if ( isset( $meta_field_def['default'] ) ) { | |
| 580 | + $default = sprintf( ' data-default="%s"', esc_attr( $meta_field_def['default'] ) ); | |
| 581 | + } | |
| 582 | + $content .= '<input type="hidden" id="' . $esc_form_key . '" name="' . $esc_form_key . '" value="' . esc_attr( $meta_value ) . '"' . $default . '/>' . "\n"; | |
| 583 | + break; | |
| 584 | + case 'select': | |
| 585 | + if ( isset( $meta_field_def['options'] ) && is_array( $meta_field_def['options'] ) && $meta_field_def['options'] !== [] ) { | |
| 586 | + $content .= '<select name="' . $esc_form_key . '" id="' . $esc_form_key . '" class="yoast' . $class . '">'; | |
| 587 | + foreach ( $meta_field_def['options'] as $val => $option ) { | |
| 588 | + $selected = selected( $meta_value, $val, false ); | |
| 589 | + $content .= '<option ' . $selected . ' value="' . esc_attr( $val ) . '">' . esc_html( $option ) . '</option>'; | |
| 590 | + } | |
| 591 | + unset( $val, $option, $selected ); | |
| 592 | + $content .= '</select>'; | |
| 593 | + } | |
| 594 | + break; | |
| 595 | + | |
| 596 | + case 'multiselect': | |
| 597 | + if ( isset( $meta_field_def['options'] ) && is_array( $meta_field_def['options'] ) && $meta_field_def['options'] !== [] ) { | |
| 598 | + | |
| 599 | + // Set $meta_value as $selected_arr. | |
| 600 | + $selected_arr = $meta_value; | |
| 601 | + | |
| 602 | + // If the multiselect field is 'meta-robots-adv' we should explode on ,. | |
| 603 | + if ( $key === 'meta-robots-adv' ) { | |
| 604 | + $selected_arr = explode( ',', $meta_value ); | |
| 605 | + } | |
| 606 | + | |
| 607 | + if ( ! is_array( $selected_arr ) ) { | |
| 608 | + $selected_arr = (array) $selected_arr; | |
| 609 | + } | |
| 610 | + | |
| 611 | + $options_count = count( $meta_field_def['options'] ); | |
| 612 | + | |
| 613 | + $content .= '<select multiple="multiple" size="' . esc_attr( $options_count ) . '" name="' . $esc_form_key . '[]" id="' . $esc_form_key . '" class="yoast' . $class . '"' . $aria_describedby . '>'; | |
| 614 | + foreach ( $meta_field_def['options'] as $val => $option ) { | |
| 615 | + $selected = ''; | |
| 616 | + if ( in_array( $val, $selected_arr, true ) ) { | |
| 617 | + $selected = ' selected="selected"'; | |
| 618 | + } | |
| 619 | + $content .= '<option ' . $selected . ' value="' . esc_attr( $val ) . '">' . esc_html( $option ) . '</option>'; | |
| 620 | + } | |
| 621 | + $content .= '</select>'; | |
| 622 | + unset( $val, $option, $selected, $selected_arr, $options_count ); | |
| 623 | + } | |
| 624 | + break; | |
| 625 | + | |
| 626 | + case 'checkbox': | |
| 627 | + $checked = checked( $meta_value, 'on', false ); | |
| 628 | + $expl = ( isset( $meta_field_def['expl'] ) ) ? esc_html( $meta_field_def['expl'] ) : ''; | |
| 629 | + $content .= '<input type="checkbox" id="' . $esc_form_key . '" name="' . $esc_form_key . '" ' . $checked . ' value="on" class="yoast' . $class . '"' . $aria_describedby . '/> <label for="' . $esc_form_key . '">' . $expl . '</label>'; | |
| 630 | + unset( $checked, $expl ); | |
| 631 | + break; | |
| 632 | + | |
| 633 | + case 'radio': | |
| 634 | + if ( isset( $meta_field_def['options'] ) && is_array( $meta_field_def['options'] ) && $meta_field_def['options'] !== [] ) { | |
| 635 | + foreach ( $meta_field_def['options'] as $val => $option ) { | |
| 636 | + $checked = checked( $meta_value, $val, false ); | |
| 637 | + $content .= '<input type="radio" ' . $checked . ' id="' . $esc_form_key . '_' . esc_attr( $val ) . '" name="' . $esc_form_key . '" value="' . esc_attr( $val ) . '"/> <label for="' . $esc_form_key . '_' . esc_attr( $val ) . '">' . esc_html( $option ) . '</label> '; | |
| 638 | + } | |
| 639 | + unset( $val, $option, $checked ); | |
| 640 | + } | |
| 641 | + break; | |
| 642 | + } | |
| 643 | + | |
| 644 | + $html = ''; | |
| 645 | + if ( $content === '' ) { | |
| 646 | + $content = apply_filters_deprecated( 'wpseo_do_meta_box_field_' . $key, [ $content, $meta_value, $esc_form_key, $meta_field_def, $key ], 'Yoast SEO 23.5', '', 'do_meta_box is deprecated' ); | |
| 647 | + } | |
| 648 | + | |
| 649 | + if ( $content !== '' ) { | |
| 650 | + | |
| 651 | + $title = esc_html( $meta_field_def['title'] ); | |
| 652 | + | |
| 653 | + // By default, use the field title as a label element. | |
| 654 | + $label = '<label for="' . $esc_form_key . '">' . $title . '</label>'; | |
| 655 | + | |
| 656 | + // Set the inline help and help panel, if any. | |
| 657 | + $help_button = ''; | |
| 658 | + $help_panel = ''; | |
| 659 | + if ( isset( $meta_field_def['help'] ) && $meta_field_def['help'] !== '' ) { | |
| 660 | + $help = new WPSEO_Admin_Help_Panel( $key, $meta_field_def['help-button'], $meta_field_def['help'] ); | |
| 661 | + $help_button = $help->get_button_html(); | |
| 662 | + $help_panel = $help->get_panel_html(); | |
| 663 | + } | |
| 664 | + | |
| 665 | + // If it's a set of radio buttons, output proper fieldset and legend. | |
| 666 | + if ( $meta_field_def['type'] === 'radio' ) { | |
| 667 | + return '<fieldset><legend>' . $title . '</legend>' . $help_button . $help_panel . $content . $description . '</fieldset>'; | |
| 668 | + } | |
| 669 | + | |
| 670 | + // If it's a single checkbox, ignore the title. | |
| 671 | + if ( $meta_field_def['type'] === 'checkbox' ) { | |
| 672 | + $label = ''; | |
| 673 | + } | |
| 674 | + | |
| 675 | + // Other meta box content or form fields. | |
| 676 | + if ( $meta_field_def['type'] === 'hidden' ) { | |
| 677 | + $html = $content; | |
| 678 | + } | |
| 679 | + else { | |
| 680 | + $html = $label . $description . $help_button . $help_panel . $content; | |
| 681 | + } | |
| 682 | + } | |
| 683 | + | |
| 684 | + return $html; | |
| 452 | 685 | } |
| 453 | 686 | |
| 454 | 687 | /** |
| 455 | 688 | * Saves the WP SEO metadata for posts. |