| @@ -1,0 +1,170 @@ | ||
| 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( 'WpssoEditVisibility' ) ) { | |
| 19 | + | |
| 20 | + class WpssoEditVisibility { | |
| 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_visibility_rows' => 4, | |
| 38 | + 'mb_sso_edit_visibility_robots_rows' => 4, | |
| 39 | + ), PHP_INT_MIN ); // Run before any add-on filters. | |
| 40 | + } | |
| 41 | + | |
| 42 | + public function filter_mb_sso_edit_visibility_rows( $table_rows, $form, $head_info, $mod ) { | |
| 43 | + | |
| 44 | + $canonical_url_msg = $this->p->msgs->maybe_seo_tag_disabled( 'link rel canonical' ); | |
| 45 | + $canonical_disabled = $canonical_url_msg ? true : false; | |
| 46 | + $def_canonical_url = $this->p->util->get_canonical_url( $mod, $add_page = false, $md_key = '' ); | |
| 47 | + $redirect_disabled = $this->p->util->is_redirect_disabled(); | |
| 48 | + $def_redirect_url = $this->p->util->get_redirect_url( $mod, $mod_id = null, $md_key = '' ); | |
| 49 | + | |
| 50 | + $form_rows = array( | |
| 51 | + 'canonical_url' => $mod[ 'is_public' ] ? array( | |
| 52 | + 'th_class' => 'medium', | |
| 53 | + 'label' => _x( 'Canonical URL', 'option label', 'wpsso' ), | |
| 54 | + 'tooltip' => 'meta-canonical_url', | |
| 55 | + 'content' => $form->get_input( 'canonical_url', $css_class = 'wide', $css_id = '', | |
| 56 | + $max_len = 0, $def_canonical_url, $canonical_disabled ) . ' ' . $canonical_url_msg, | |
| 57 | + ) : '', | |
| 58 | + 'redirect_url' => $mod[ 'is_public' ] ? array( | |
| 59 | + 'th_class' => 'medium', | |
| 60 | + 'label' => _x( '301 Redirect URL', 'option label', 'wpsso' ), | |
| 61 | + 'tooltip' => 'meta-redirect_url', | |
| 62 | + 'content' => $form->get_input( 'redirect_url', $css_class = 'wide', $css_id = '', | |
| 63 | + $max_len = 0, $def_redirect_url, $redirect_disabled ), | |
| 64 | + ) : '', | |
| 65 | + ); | |
| 66 | + | |
| 67 | + $table_rows = $form->get_md_form_rows( $table_rows, $form_rows, $head_info, $mod ); | |
| 68 | + | |
| 69 | + foreach( array( | |
| 70 | + 'wpsso_mb_sso_edit_visibility_robots_rows', | |
| 71 | + ) as $filter_name ) { | |
| 72 | + | |
| 73 | + if ( $this->p->debug->enabled ) { | |
| 74 | + | |
| 75 | + $this->p->debug->log( 'applying filters "' . $filter_name . '"' ); | |
| 76 | + } | |
| 77 | + | |
| 78 | + $table_rows = apply_filters( $filter_name, $table_rows, $form, $head_info, $mod ); | |
| 79 | + } | |
| 80 | + | |
| 81 | + return $table_rows; | |
| 82 | + } | |
| 83 | + | |
| 84 | + public function filter_mb_sso_edit_visibility_robots_rows( $table_rows, $form, $head_info, $mod ) { | |
| 85 | + | |
| 86 | + $robots_msg = $this->p->msgs->maybe_seo_tag_disabled( 'meta name robots' ); | |
| 87 | + $robots_disabled = $robots_msg ? true : false; | |
| 88 | + | |
| 89 | + $form_rows = array( | |
| 90 | + 'subsection_robots_meta' => array( | |
| 91 | + 'td_class' => 'subsection', | |
| 92 | + 'header' => 'h4', | |
| 93 | + 'label' => _x( 'Robots Meta', 'metabox title', 'wpsso' ), | |
| 94 | + ), | |
| 95 | + 'robots_disabled' => array( | |
| 96 | + 'table_row' => $robots_disabled ? '<td colspan="2">' . $robots_msg . '</td>' : '', | |
| 97 | + ), | |
| 98 | + 'robots_noarchive' => array( | |
| 99 | + 'th_class' => 'medium', | |
| 100 | + 'label' => _x( 'No Archive', 'option label', 'wpsso' ), | |
| 101 | + 'tooltip' => 'meta-robots_noarchive', | |
| 102 | + 'content' => $form->get_checkbox( 'robots_noarchive', $css_class = '', $css_id = '', $robots_disabled ) . ' ' . | |
| 103 | + _x( 'do not show a cached link in search results', 'option comment', 'wpsso' ), | |
| 104 | + ), | |
| 105 | + 'robots_nofollow' => array( | |
| 106 | + 'th_class' => 'medium', | |
| 107 | + 'label' => _x( 'No Follow', 'option label', 'wpsso' ), | |
| 108 | + 'tooltip' => 'meta-robots_nofollow', | |
| 109 | + 'content' => $form->get_checkbox( 'robots_nofollow', $css_class = '', $css_id = '', $robots_disabled ) . ' ' . | |
| 110 | + _x( 'do not follow links on this webpage', 'option comment', 'wpsso' ), | |
| 111 | + ), | |
| 112 | + 'robots_noimageindex' => array( | |
| 113 | + 'th_class' => 'medium', | |
| 114 | + 'label' => _x( 'No Image Index', 'option label', 'wpsso' ), | |
| 115 | + 'tooltip' => 'meta-robots_noimageindex', | |
| 116 | + 'content' => $form->get_checkbox( 'robots_noimageindex', $css_class = '', $css_id = '', $robots_disabled ) . ' ' . | |
| 117 | + _x( 'do not index images on this webpage', 'option comment', 'wpsso' ), | |
| 118 | + ), | |
| 119 | + 'robots_noindex' => array( | |
| 120 | + 'th_class' => 'medium', | |
| 121 | + 'label' => _x( 'No Index', 'option label', 'wpsso' ), | |
| 122 | + 'tooltip' => 'meta-robots_noindex', | |
| 123 | + 'content' => $form->get_checkbox( 'robots_noindex', $css_class = '', $css_id = '', $robots_disabled ) . ' ' . | |
| 124 | + _x( 'do not show this webpage in search results', 'option comment', 'wpsso' ), | |
| 125 | + ), | |
| 126 | + 'robots_nosnippet' => array( | |
| 127 | + 'th_class' => 'medium', | |
| 128 | + 'label' => _x( 'No Snippet', 'option label', 'wpsso' ), | |
| 129 | + 'tooltip' => 'meta-robots_nosnippet', | |
| 130 | + 'content' => $form->get_checkbox( 'robots_nosnippet', $css_class = '', $css_id = '', $robots_disabled ) . ' ' . | |
| 131 | + _x( 'do not show a text snippet or a video preview in search results', 'option comment', 'wpsso' ), | |
| 132 | + ), | |
| 133 | + 'robots_notranslate' => array( | |
| 134 | + 'th_class' => 'medium', | |
| 135 | + 'label' => _x( 'No Translate', 'option label', 'wpsso' ), | |
| 136 | + 'tooltip' => 'meta-robots_notranslate', | |
| 137 | + 'content' => $form->get_checkbox( 'robots_notranslate', $css_class = '', $css_id = '', $robots_disabled ) . ' ' . | |
| 138 | + _x( 'do not offer translation of this webpage in search results', 'option comment', 'wpsso' ), | |
| 139 | + ), | |
| 140 | + 'robots_max_snippet' => array( | |
| 141 | + 'th_class' => 'medium', | |
| 142 | + 'label' => _x( 'Snippet Max. Length', 'option label', 'wpsso' ), | |
| 143 | + 'tooltip' => 'robots_max_snippet', // Use the tooltip from plugin settings. | |
| 144 | + 'content' => $form->get_input( 'robots_max_snippet', $css_class = 'chars', $css_id = '', | |
| 145 | + $len = 0, $holder = true, $robots_disabled ) . ' ' . | |
| 146 | + _x( 'characters or less', 'option comment', 'wpsso' ) . ' ' . | |
| 147 | + _x( '(-1 for no limit)', 'option comment', 'wpsso' ), | |
| 148 | + ), | |
| 149 | + 'robots_max_image_preview' => array( | |
| 150 | + 'th_class' => 'medium', | |
| 151 | + 'label' => _x( 'Image Preview Size', 'option label', 'wpsso' ), | |
| 152 | + 'tooltip' => 'robots_max_image_preview', // Use the tooltip from plugin settings. | |
| 153 | + 'content' => $form->get_select( 'robots_max_image_preview', $this->p->cf[ 'form' ][ 'robots_max_image_preview' ], | |
| 154 | + $css_class = '', $css_id = '', $is_assoc = true, $robots_disabled ), | |
| 155 | + ), | |
| 156 | + 'robots_max_video_preview' => array( | |
| 157 | + 'th_class' => 'medium', | |
| 158 | + 'label' => _x( 'Video Max. Previews', 'option label', 'wpsso' ), | |
| 159 | + 'tooltip' => 'robots_max_video_preview', // Use the tooltip from plugin settings. | |
| 160 | + 'content' => $form->get_input( 'robots_max_video_preview', $css_class = 'chars', $css_id = '', | |
| 161 | + $len = 0, $holder = true, $robots_disabled ) . | |
| 162 | + _x( 'seconds', 'option comment', 'wpsso' ) . ' ' . | |
| 163 | + _x( '(-1 for no limit)', 'option comment', 'wpsso' ), | |
| 164 | + ), | |
| 165 | + ); | |
| 166 | + | |
| 167 | + return $form->get_md_form_rows( $table_rows, $form_rows, $head_info, $mod ); | |
| 168 | + } | |
| 169 | + } | |
| 170 | +} | |