Beispiel #1
0
 /**
  *
  * Fix post_type permalink from postname to id.
  *
  * @param string $post_link The post's permalink.
  * @param \WP_Post $post The post in question.
  *
  * @return string
  */
 public function post_type_link($post_link, \WP_Post $post)
 {
     if (!$this->option->get_structure($post->post_type)) {
         return $post_link;
     }
     $rewritecode = array("%{$post->post_type}_id%");
     $rewritereplace = array($post->ID);
     return str_replace($rewritecode, $rewritereplace, $post_link);
 }
Beispiel #2
0
 /**
  *
  * set default permastruct.
  * for deactivation.
  *
  * @param array $param
  *
  */
 public function reset_rewrite_rule($param)
 {
     $args = $param['args'];
     $post_type = $param['post_type'];
     $permastruct_args = $args->rewrite;
     $permastruct_args['feed'] = $permastruct_args['feeds'];
     if ($this->option->get_structure($post_type)) {
         add_permastruct($post_type, "{$args->rewrite['slug']}/%{$post_type}%", $permastruct_args);
     }
 }
Beispiel #3
0
    /**
     *
     * setting field row.
     *
     * @param $args
     */
    public function setting_field($args)
    {
        global $wp_rewrite;
        $slash = '';
        if ($wp_rewrite->use_trailing_slashes) {
            $slash = '/';
        }
        preg_match('/sptp_(.+)_structure/', $args, $matches);
        $post_type = $matches[1];
        $post_type_object = get_post_type_object($post_type);
        $with_front = $post_type_object->rewrite['with_front'];
        $slug = trim($post_type_object->rewrite['slug'], '/');
        if (!empty($post_type_object->rewrite['original_slug'])) {
            $slug = trim($post_type_object->rewrite['original_slug'], '/');
        }
        $values = array(false, "{$slug}/%post_id%", "{$slug}/%postname%.html", "{$slug}/%post_id%.html");
        $permastruct = $this->option->get_structure($post_type);
        $disabled = $this->option->is_defined_structure($post_type);
        ?>
		<fieldset class="sptp-fieldset <?php 
        echo $with_front ? 'with-front' : '';
        ?>
">
			<?php 
        $checked = false;
        foreach ($values as $value) {
            if (!$checked) {
                $checked = $permastruct == $value;
            }
            $permalink = str_replace(array('%postname%', '%post_id%'), array('sample-post', '123'), $value);
            ?>
				<label>
					<input type="radio" name="<?php 
            echo esc_attr($args);
            ?>
_select"
					       value="<?php 
            echo esc_attr($value);
            ?>
"
						<?php 
            if (!$disabled) {
                checked($permastruct, $value);
            }
            ?>
						<?php 
            disabled($disabled);
            ?>
						/>
					<?php 
            if ($value) {
                ?>
						<code><?php 
                echo esc_html(home_url()) . '/' . $this->create_permastruct($permalink, $with_front);
                ?>
							<span
								class="slash"><?php 
                echo esc_attr($slash);
                ?>
</span></code>
					<?php 
            } else {
                ?>
						Default.
					<?php 
            }
            ?>

				</label>
				<br/>
			<?php 
        }
        ?>
			<label>
				<input type="radio" name="<?php 
        echo esc_attr($args);
        ?>
_select" value="custom"
					<?php 
        checked($checked, false);
        ?>
					<?php 
        disabled($disabled);
        ?>
 />
				<code><?php 
        echo esc_html(home_url()) . '/' . $this->create_permastruct('', $with_front);
        ?>
</code>

				<input class="regular-text code"
				       name="<?php 
        echo esc_attr("sptp_{$post_type}_structure");
        ?>
"
				       id="<?php 
        echo esc_attr("sptp_{$post_type}_structure");
        ?>
"
				       type="text" value="<?php 
        echo esc_attr($permastruct);
        ?>
"
					<?php 
        disabled($disabled);
        ?>
					/><span class="slash"><?php 
        echo esc_html($slash);
        ?>
</span>
			</label>

		</fieldset>
	<?php 
    }