| 1 |
<?php |
| 2 |
/* |
| 3 |
* License: GPLv3 |
| 4 |
* License URI: https://www.gnu.org/licenses/gpl.txt |
| 5 |
* Copyright 2020-2026 Jean-Sebastien Morisset (https://wpsso.com/) |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
|
| 10 |
die( 'These aren\'t the droids you\'re looking for.' ); |
| 11 |
} |
| 12 |
|
| 13 |
if ( ! defined( 'WPSSO_PLUGINDIR' ) ) { |
| 14 |
|
| 15 |
die( 'Do. Or do not. There is no try.' ); |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! class_exists( 'WpssoEditGeneral' ) ) { |
| 19 |
|
| 20 |
class WpssoEditGeneral { |
| 21 |
|
| 22 |
private $p; // Wpsso class object. |
| 23 |
|
| 24 |
public function __construct( &$plugin ) { |
| 25 |
|
| 26 |
$this->p =& $plugin; |
| 27 |
|
| 28 |
if ( $this->p->debug->enabled ) { |
| 29 |
|
| 30 |
$this->p->debug->mark(); |
| 31 |
} |
| 32 |
|
| 33 |
/* |
| 34 |
* See WpssoAbstractWpMeta->get_document_sso_tabs(). |
| 35 |
*/ |
| 36 |
$this->p->util->add_plugin_filters( $this, array( |
| 37 |
'mb_sso_edit_general_rows' => 4, |
| 38 |
), PHP_INT_MIN ); // Run before any add-on filters. |
| 39 |
} |
| 40 |
|
| 41 |
public function filter_mb_sso_edit_general_rows( $table_rows, $form, $head_info, $mod ) { |
| 42 |
|
| 43 |
$og_types = $this->p->og->get_og_types_select(); |
| 44 |
$schema_types = $this->p->schema->get_schema_types_select(); |
| 45 |
$primary_terms = $this->p->post->get_primary_terms( $mod, $mod[ 'post_primary_tax_slug' ], $output = 'names' ); |
| 46 |
$input_limits = WpssoConfig::get_input_limits(); // Uses a local cache. |
| 47 |
|
| 48 |
/* |
| 49 |
* Default option values. |
| 50 |
*/ |
| 51 |
$def_seo_title = $this->p->page->get_title( $mod, $md_key = '', $max_len = 'seo_title' ); |
| 52 |
$def_og_title = $this->p->page->get_title( $mod, $md_key = 'seo_title', $max_len = 'og_title' ); |
| 53 |
$def_tc_title = $this->p->page->get_title( $mod, $md_key = 'og_title', $max_len = 'tc_title' ); |
| 54 |
|
| 55 |
$def_seo_desc = $this->p->page->get_description( $mod, $md_key = '', $max_len = 'seo_desc' ); |
| 56 |
$def_og_desc = $this->p->page->get_description( $mod, $md_key = 'seo_desc', $max_len = 'og_desc' ); |
| 57 |
$def_pin_img_desc = $this->p->page->get_description( $mod, $md_key = 'og_desc', $max_len = 'pin_img_desc' ); |
| 58 |
$def_tc_desc = $this->p->page->get_description( $mod, $md_key = 'og_desc', $max_len = 'tc_desc' ); |
| 59 |
|
| 60 |
/* |
| 61 |
* WpssoMessages->maybe_seo_title_disabled() returns a message if: |
| 62 |
* |
| 63 |
* - An SEO plugin is active. |
| 64 |
* - The theme does not support the 'title-tag' feature. |
| 65 |
* - The WPSSO_TITLE_TAG_DISABLE constant is true. |
| 66 |
* - The 'plugin_title_tag' option is not 'seo_title'. |
| 67 |
*/ |
| 68 |
$seo_title_msg = $this->p->msgs->maybe_seo_title_disabled(); |
| 69 |
$seo_desc_msg = $this->p->msgs->maybe_seo_tag_disabled( 'meta name description' ); |
| 70 |
$pin_img_msg = $this->p->msgs->maybe_pin_img_disabled(); |
| 71 |
|
| 72 |
$seo_title_disabled = $seo_title_msg ? true : false; |
| 73 |
$seo_desc_disabled = $seo_desc_msg ? true : false; |
| 74 |
$pin_img_disabled = $pin_img_msg ? true : false; |
| 75 |
|
| 76 |
/* |
| 77 |
* Metabox form rows. |
| 78 |
*/ |
| 79 |
$form_rows = array( |
| 80 |
'attach_img_crop' => $mod[ 'is_attachment' ] && wp_attachment_is( 'image', $mod[ 'id' ] ) ? array( |
| 81 |
'th_class' => 'medium', |
| 82 |
'label' => _x( 'Crop Area', 'option label', 'wpsso' ), |
| 83 |
'tooltip' => 'meta-og_img_crop_area', |
| 84 |
'content' => $form->get_input_image_crop_area( 'attach_img', $add_none = true ), |
| 85 |
) : array(), |
| 86 |
'og_schema_type' => array( |
| 87 |
'th_class' => 'medium', |
| 88 |
'label' => _x( 'Schema Type', 'option label', 'wpsso' ), |
| 89 |
'tooltip' => 'meta-og_schema_type', |
| 90 |
'content' => $form->get_select( 'schema_type', $schema_types, $css_class = 'schema_type', $css_id = 'og_schema_type', |
| 91 |
$is_assoc = true, $is_disabled = false, $selected = false, |
| 92 |
$event_names = array( 'on_focus_load_json', 'on_change_unhide_rows' ), |
| 93 |
$event_args = array( |
| 94 |
'json_var' => 'schema_types', |
| 95 |
'exp_secs' => WPSSO_CACHE_SELECT_JSON_EXP_SECS, // Create and read from a javascript URL. |
| 96 |
'is_transl' => true, // No label translation required. |
| 97 |
'is_sorted' => true, // No label sorting required. |
| 98 |
) |
| 99 |
), |
| 100 |
), |
| 101 |
'og_type' => array( |
| 102 |
'th_class' => 'medium', |
| 103 |
'label' => _x( 'Open Graph Type', 'option label', 'wpsso' ), |
| 104 |
'tooltip' => 'meta-og_type', |
| 105 |
'content' => $form->get_select( 'og_type', $og_types, $css_class = 'og_type', $css_id = '', |
| 106 |
$is_assoc = true, $is_disabled = false, $selected = false, |
| 107 |
$event_names = array( 'on_change_unhide_rows' ) ), |
| 108 |
), |
| 109 |
'primary_term_id' => ! empty( $primary_terms ) ? array( // Show the option if we have post category terms. |
| 110 |
'th_class' => 'medium', |
| 111 |
'label' => _x( 'Primary Category', 'option label', 'wpsso' ), |
| 112 |
'tooltip' => 'meta-primary_term_id', |
| 113 |
'content' => $form->get_select( 'primary_term_id', $primary_terms, $css_class = 'primary_term_id', $css_id = '', $is_assoc = true ), |
| 114 |
) : '', |
| 115 |
'seo_title' => $mod[ 'is_public' ] ? array( |
| 116 |
'tr_class' => $seo_title_disabled ? 'hide_in_basic' : '', |
| 117 |
'th_class' => 'medium', |
| 118 |
'label' => _x( 'SEO Title Tag', 'option label', 'wpsso' ), |
| 119 |
'tooltip' => 'meta-seo_title', |
| 120 |
'content' => $form->get_input( 'seo_title', $css_class = 'wide', $css_id = '', |
| 121 |
$input_limits[ 'seo_title' ], $def_seo_title, $seo_title_disabled ) . ' ' . $seo_title_msg, |
| 122 |
) : '', |
| 123 |
'seo_desc' => $mod[ 'is_public' ] ? array( |
| 124 |
'tr_class' => $seo_desc_disabled ? 'hide_in_basic' : '', |
| 125 |
'th_class' => 'medium', |
| 126 |
'label' => _x( 'SEO Meta Description', 'option label', 'wpsso' ), |
| 127 |
'tooltip' => 'meta-seo_desc', |
| 128 |
'content' => $form->get_textarea( 'seo_desc', $css_class = '', $css_id = '', |
| 129 |
$input_limits[ 'seo_desc' ], $def_seo_desc, $seo_desc_disabled ) . ' ' . $seo_desc_msg, |
| 130 |
) : '', |
| 131 |
'og_title' => $mod[ 'is_public' ] ? array( |
| 132 |
'th_class' => 'medium', |
| 133 |
'label' => _x( 'Social Title', 'option label', 'wpsso' ), |
| 134 |
'tooltip' => 'meta-og_title', |
| 135 |
'content' => $form->get_input_dep( 'og_title', $css_class = 'wide', $css_id = '', |
| 136 |
$input_limits[ 'og_title' ], $def_og_title, $is_disabled = false, $dep_id = 'seo_title' ), |
| 137 |
) : '', |
| 138 |
'og_desc' => $mod[ 'is_public' ] ? array( |
| 139 |
'th_class' => 'medium', |
| 140 |
'label' => _x( 'Social Description', 'option label', 'wpsso' ), |
| 141 |
'tooltip' => 'meta-og_desc', |
| 142 |
'content' => $form->get_textarea_dep( 'og_desc', $css_class = '', $css_id = '', |
| 143 |
$input_limits[ 'og_desc' ], $def_og_desc, $is_disabled = false, $dep_id = 'seo_desc' ), |
| 144 |
) : '', |
| 145 |
'pin_img_desc' => $mod[ 'is_public' ] ? array( |
| 146 |
'tr_class' => $pin_img_disabled ? 'hide_in_basic' : '', |
| 147 |
'th_class' => 'medium', |
| 148 |
'label' => _x( 'Pinterest Description', 'option label', 'wpsso' ), |
| 149 |
'tooltip' => 'meta-pin_img_desc', |
| 150 |
'content' => $form->get_textarea_dep( 'pin_img_desc', $css_class = '', $css_id = '', |
| 151 |
$input_limits[ 'pin_img_desc' ], $def_pin_img_desc, $pin_img_disabled, $dep_id = 'og_desc' ) . $pin_img_msg, |
| 152 |
) : '', |
| 153 |
'tc_title' => $mod[ 'is_public' ] ? array( |
| 154 |
'th_class' => 'medium', |
| 155 |
'label' => _x( 'X (Twitter) Card Title', 'option label', 'wpsso' ), |
| 156 |
'tooltip' => 'meta-tc_title', |
| 157 |
'content' => $form->get_input_dep( 'tc_title', $css_class = 'wide', $css_id = '', |
| 158 |
$input_limits[ 'tc_title' ], $def_tc_title, $is_disabled = false, $dep_id = 'og_title' ), |
| 159 |
) : '', |
| 160 |
'tc_desc' => $mod[ 'is_public' ] ? array( |
| 161 |
'th_class' => 'medium', |
| 162 |
'label' => _x( 'X (Twitter) Card Description', 'option label', 'wpsso' ), |
| 163 |
'tooltip' => 'meta-tc_desc', |
| 164 |
'content' => $form->get_textarea_dep( 'tc_desc', $css_class = '', $css_id = '', |
| 165 |
$input_limits[ 'tc_desc' ], $def_tc_desc, $is_disabled = false, $dep_id = 'og_desc' ), |
| 166 |
) : '', |
| 167 |
); |
| 168 |
|
| 169 |
return $form->get_md_form_rows( $table_rows, $form_rows, $head_info, $mod ); |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
|