CPTP_Util::get_permalink_structure PHP Метод

    public static function get_permalink_structure($post_type)
    {
        if (is_string($post_type)) {
            $pt_object = get_post_type_object($post_type);
        } else {
            $pt_object = $post_type;
        }
        if (!empty($pt_object->cptp_permalink_structure)) {
            $structure = $pt_object->cptp_permalink_structure;
        } else {
            $structure = get_option($pt_object->name . '_structure');
        }
        return apply_filters('CPTP_' . $pt_object->name . '_structure', $structure);
    }

Usage Example

Пример #1
0
 public function setting_structure_callback_function($option)
 {
     $post_type = str_replace('_structure', '', $option);
     $pt_object = get_post_type_object($post_type);
     $slug = $pt_object->rewrite['slug'];
     $with_front = $pt_object->rewrite['with_front'];
     $value = CPTP_Util::get_permalink_structure($post_type);
     $disabled = false;
     if (isset($pt_object->cptp_permalink_structure) and $pt_object->cptp_permalink_structure) {
         $disabled = true;
     }
     if (!$value) {
         $value = CPTP_DEFAULT_PERMALINK;
     }
     global $wp_rewrite;
     $front = substr($wp_rewrite->front, 1);
     if ($front and $with_front) {
         $slug = $front . $slug;
     }
     echo '<p><code>' . home_url() . '/' . esc_html($slug) . '</code> <input name="' . esc_attr($option) . '" id="' . esc_attr($option) . '" type="text" class="regular-text code ' . $this->disabled_string($disabled) . '" value="' . $value . '" ' . $this->disabled_string($disabled) . ' /></p>';
     echo '<p>has_archive: <code>';
     echo $pt_object->has_archive ? 'true' : 'false';
     echo '</code> / ';
     echo 'with_front: <code>';
     echo $pt_object->rewrite['with_front'] ? 'true' : 'false';
     echo '</code></p>';
 }
All Usage Examples Of CPTP_Util::get_permalink_structure