helper.php
3 years ago
share-style-settings.php
3 years ago
social-share-style.php
3 years ago
user-helper.php
3 years ago
view-helper.php
3 years ago
share-style-settings.php
106 lines
| 1 | <?php |
| 2 | namespace WP_Social\Helper; |
| 3 | use WP_Social\Traits\Singleton; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | class Share_Style_Settings{ |
| 8 | |
| 9 | use Singleton; |
| 10 | |
| 11 | public static $post_type = ['post', 'page']; |
| 12 | public function social_share_style_markup(){ |
| 13 | |
| 14 | // $post is already set, and contains an object: the WordPress post |
| 15 | global $post; |
| 16 | $values = get_post_custom( $post->ID ); |
| 17 | $check = isset( $values['social_share_style'] ) ? esc_attr( $values['social_share_style'][0] ) : 'global'; |
| 18 | // We'll use this nonce field later on when saving. |
| 19 | wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' ); |
| 20 | |
| 21 | ?> |
| 22 | <ul> |
| 23 | <li> |
| 24 | <strong><?php echo esc_html__('Choose where to show share buttons.', 'wp-social') ?></strong> |
| 25 | </li> |
| 26 | <li> |
| 27 | <input type="radio" id="social_share_global" name="social_share_style" value="global" |
| 28 | <?php checked( $check, 'global') ?> |
| 29 | /> |
| 30 | <label for="social_share_global"> <?php echo esc_html__('Global Setting', 'wp-social') ?> </label> |
| 31 | </li> |
| 32 | |
| 33 | <li> |
| 34 | <input type="radio" id="social_share_after_content" name="social_share_style" value="after_content" |
| 35 | <?php checked( $check, 'after_content') ?> |
| 36 | |
| 37 | /> |
| 38 | <label for="social_share_after_content"><?php echo esc_html__('After Content', 'wp-social') ?></label> |
| 39 | </li> |
| 40 | |
| 41 | <li> |
| 42 | <input type="radio" id="social_share_before_content" name="social_share_style" value="before_content" |
| 43 | <?php checked( $check, 'before_content') ?> |
| 44 | /> |
| 45 | <label for="social_share_before_content"><?php echo esc_html__('Before Content', 'wp-social') ?></label> |
| 46 | </li> |
| 47 | |
| 48 | <li> |
| 49 | <input type="radio" id="social_share_both" name="social_share_style" value="both_content" |
| 50 | <?php checked( $check, 'both_content') ?> |
| 51 | /> |
| 52 | <label for="social_share_both"><?php echo esc_html__('Before & After Content', 'wp-social') ?></label> |
| 53 | </li> |
| 54 | |
| 55 | <li> |
| 56 | <input type="radio" id="social_share_disable" name="social_share_style" value="no_content" |
| 57 | <?php checked( $check, 'no_content') ?> |
| 58 | /> |
| 59 | <label for="social_share_disable"><?php echo esc_html__('Disable', 'wp-social') ?></label> |
| 60 | </li> |
| 61 | </ul> |
| 62 | |
| 63 | <?php |
| 64 | |
| 65 | } |
| 66 | |
| 67 | public function wp_social_share_save( $post_id ){ |
| 68 | // Bail if we're doing an auto save |
| 69 | if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; |
| 70 | |
| 71 | // if our nonce isn't there, or we can't verify it, bail |
| 72 | if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return; |
| 73 | |
| 74 | // if our current user can't edit this post, bail |
| 75 | if( !current_user_can( 'edit_post', $post_id ) ) return; |
| 76 | |
| 77 | if( isset( $_POST['social_share_style'] ) ){ |
| 78 | update_post_meta( $post_id, 'social_share_style', sanitize_text_field( $_POST['social_share_style'] ) ); |
| 79 | }else{ |
| 80 | update_post_meta( $post_id, 'social_share_style', esc_attr( 'global' ) ); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | |
| 85 | public function wp_social_share_style_settings ($post_type, $id) { |
| 86 | if( in_array($post_type, self::$post_type) ){ |
| 87 | add_meta_box( 'wp-social-plugin', esc_html__('WP Social Share Style Settings', 'wp-social'), [$this, 'social_share_style_markup'], $post_type , 'normal', 'high'); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | public function init(){ |
| 92 | add_action( 'add_meta_boxes', [ $this, 'wp_social_share_style_settings'] , 10, 2 ); |
| 93 | add_action( 'save_post', [$this, 'wp_social_share_save']); |
| 94 | |
| 95 | } |
| 96 | |
| 97 | public static function instance() { |
| 98 | if(!self::$instance) { |
| 99 | self::$instance = new static(); |
| 100 | } |
| 101 | |
| 102 | return self::$instance; |
| 103 | } |
| 104 | |
| 105 | } |
| 106 |