| 1 |
<?php |
| 2 |
|
| 3 |
class SimpleTags_Admin_Post_Settings { |
| 4 |
/** |
| 5 |
* Constructor |
| 6 |
* |
| 7 |
* @return void |
| 8 |
* @author WebFactory Ltd |
| 9 |
*/ |
| 10 |
public function __construct() { |
| 11 |
|
| 12 |
if( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_auto_links' )) || (1 === (int) SimpleTags_Plugin::get_option_value( 'active_auto_terms') ) ){ |
| 13 |
// Save tags from advanced input |
| 14 |
add_action( 'save_post', array( __CLASS__, 'save_post' ), 10, 1 ); |
| 15 |
// Box for advanced tags |
| 16 |
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ), 10, 1 ); |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Register a new box for TaxoPress settings |
| 22 |
* |
| 23 |
* @param string $post_type |
| 24 |
* |
| 25 |
* @return void |
| 26 |
* @author WebFactory Ltd |
| 27 |
*/ |
| 28 |
public static function add_meta_boxes( $post_type ) { |
| 29 |
|
| 30 |
$click_terms = taxopress_current_post_suggest_terms(); |
| 31 |
$autolink = taxopress_post_type_autolink_autolink(); |
| 32 |
|
| 33 |
if(!is_array($click_terms) && !is_array($autolink)){ |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
// Auto terms for this CPT ? |
| 38 |
add_meta_box( 'simpletags-settings', __( 'TaxoPress', 'simple-tags' ), array( |
| 39 |
__CLASS__, |
| 40 |
'metabox' |
| 41 |
), $post_type, 'side', 'low' ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Build HTML of form |
| 46 |
* |
| 47 |
* @param object $post |
| 48 |
* |
| 49 |
* @return void |
| 50 |
* @author WebFactory Ltd |
| 51 |
*/ |
| 52 |
public static function metabox( $post ) { |
| 53 |
if ( ! isset( $post->post_type ) ) { |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
// Auto terms for this CPT ? |
| 58 |
if(1 === (int) SimpleTags_Plugin::get_option_value( 'active_auto_terms' )){ |
| 59 |
$meta_value = get_post_meta( $post->ID, '_exclude_autotags', true ); |
| 60 |
echo '<p>' . "\n"; |
| 61 |
echo '<label><input type="checkbox" name="exclude_autotags" value="true" ' . checked( esc_attr($meta_value), true, false ) . ' /> ' . esc_html__( 'Disable Auto Terms', 'simple-tags' ) . '</label><br />' . "\n"; |
| 62 |
echo '</p>' . "\n"; |
| 63 |
echo '<input type="hidden" name="_meta_autotags" value="true" />'; |
| 64 |
} |
| 65 |
|
| 66 |
if(1 === (int) SimpleTags_Plugin::get_option_value( 'active_auto_links' )){ |
| 67 |
$meta_value = get_post_meta( $post->ID, '_exclude_autolinks', true ); |
| 68 |
echo '<p>' . "\n"; |
| 69 |
echo '<label><input type="checkbox" name="exclude_autolinks" value="true" ' . checked( esc_attr($meta_value), true, false ) . ' /> ' . esc_html__( 'Disable Auto Links', 'simple-tags' ) . '</label><br />' . "\n"; |
| 70 |
echo '</p>' . "\n"; |
| 71 |
echo '<input type="hidden" name="_meta_autolink" value="true" />'; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Save this settings in post meta, delete if no exclude, clean DB :) |
| 77 |
* |
| 78 |
* @param integer $object_id |
| 79 |
* |
| 80 |
* @return void |
| 81 |
* @author WebFactory Ltd |
| 82 |
*/ |
| 83 |
public static function save_post( $object_id = 0 ) { |
| 84 |
if ( isset( $_POST['_meta_autotags'] ) && 'true' === $_POST['_meta_autotags'] ) { |
| 85 |
if ( isset( $_POST['exclude_autotags'] ) ) { |
| 86 |
update_post_meta( $object_id, '_exclude_autotags', true ); |
| 87 |
} else { |
| 88 |
delete_post_meta( $object_id, '_exclude_autotags' ); |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
if ( isset( $_POST['_meta_autolink'] ) && 'true' === $_POST['_meta_autolink'] ) { |
| 93 |
if ( isset( $_POST['exclude_autolinks'] ) ) { |
| 94 |
update_post_meta( $object_id, '_exclude_autolinks', true ); |
| 95 |
} else { |
| 96 |
delete_post_meta( $object_id, '_exclude_autolinks' ); |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
|