Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Category Links To
- Plugin URI: http://ru.forums.wordpress.org/topic/43423
- Description: Allows you to make a WordPress category link to an external URL of your choosing, instead of its WordPress URL.
- Author: Sergey Biryukov
- Author URI: http://profiles.wordpress.org/sergeybiryukov/
- Version: 0.1
- */
- class Category_Links_To {
- function __construct() {
- add_filter( 'category_add_form_fields', array( $this, 'add_field_to_add_category_form' ), 1 );
- add_filter( 'category_edit_form_fields', array( $this, 'add_field_to_edit_category_form' ), 1 );
- add_filter( 'category_link', array( $this, 'filter_category_link' ), 10, 2 );
- add_action( 'created_category', array( $this, 'save_category_link' ) );
- add_action( 'edited_category', array( $this, 'save_category_link' ) );
- }
- function get_options() {
- return get_option( 'category_links_to', array() );
- }
- function save_options( $options ) {
- update_option( 'category_links_to', $options );
- }
- function add_field_to_add_category_form() { ?>
- <div class="form-field term-link-wrap">
- <label for="tag-link">Ссылка</label>
- <input name="term-link" id="tag-link" type="text" value="" size="40" />
- <p>Здесь можно указать адрес, на который будет вести ссылка на рубрику.</p>
- </div>
- <?php
- }
- function add_field_to_edit_category_form( $term ) {
- $options = $this->get_options();
- if ( isset( $options[ $term->term_id ] ) ) {
- $term_link = $options[ $term->term_id ];
- } else {
- $term_link = '';
- }
- ?>
- <tr class="form-field term-link-wrap">
- <th scope="row"><label for="link">Ссылка</label></th>
- <td><input name="term-link" id="link" type="text" value="<?php echo esc_attr( $term_link ); ?>" size="40" />
- <p class="description">Здесь можно указать адрес, на который будет вести ссылка на рубрику.</p></td>
- </tr>
- <?php
- }
- function filter_category_link( $term_link, $term_id ) {
- $options = $this->get_options();
- if ( isset( $options[ $term_id ] ) ) {
- $term_link = esc_url( $options[ $term_id ] );
- }
- return $term_link;
- }
- function save_category_link( $term_id ) {
- $options = $this->get_options();
- if ( ! empty( $_POST['term-link'] ) ) {
- $options[ $term_id ] = esc_url_raw( $_POST['term-link'] );
- } else {
- unset( $options[ $term_id ] );
- }
- $this->save_options( $options );
- }
- }
- new Category_Links_To;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement