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