jetpack-likes-settings.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <?php
  2. class Jetpack_Likes_Settings {
  3. function __construct() {
  4. $this->in_jetpack = ! ( defined( 'IS_WPCOM' ) && IS_WPCOM );
  5. }
  6. /**
  7. * Replaces the "Sharing" title for the post screen metabox with "Likes and Shares"
  8. */
  9. public function add_likes_to_sharing_meta_box_title() {
  10. return __( 'Likes and Shares', 'jetpack' );
  11. }
  12. /**
  13. * Adds a metabox to the post screen if the sharing one doesn't currently exist.
  14. */
  15. public function add_meta_box() {
  16. if (
  17. /**
  18. * Allow disabling of the Likes metabox on the post editor screen.
  19. *
  20. * @module likes
  21. *
  22. * @since 2.2.0
  23. *
  24. * @param bool false Should the Likes metabox be disabled? Default to false.
  25. */
  26. apply_filters( 'post_flair_disable', false )
  27. ) {
  28. return;
  29. }
  30. $post_types = get_post_types( array( 'public' => true ) );
  31. /**
  32. * Filters the Likes metabox title.
  33. *
  34. * @module likes
  35. *
  36. * @since 2.2.0
  37. *
  38. * @param string Likes metabox title. Default to "Likes".
  39. */
  40. $title = apply_filters( 'likes_meta_box_title', __( 'Likes', 'jetpack' ) );
  41. foreach( $post_types as $post_type ) {
  42. add_meta_box( 'likes_meta', $title, array( $this, 'meta_box_content' ), $post_type, 'side', 'default' );
  43. }
  44. }
  45. /**
  46. * Shows the likes option in the post screen metabox.
  47. */
  48. public function meta_box_content( $post ) {
  49. $post_id = ! empty( $post->ID ) ? (int) $post->ID : get_the_ID();
  50. $checked = true;
  51. $disabled = ! $this->is_enabled_sitewide();
  52. $switched_status = get_post_meta( $post_id, 'switch_like_status', true );
  53. if ( $disabled && empty( $switched_status ) || ! $disabled && $switched_status === '0' ) {
  54. $checked = false;
  55. }
  56. /**
  57. * Fires before the Likes meta box content in the post editor.
  58. *
  59. * @module likes
  60. *
  61. * @since 2.2.0
  62. *
  63. * @param WP_Post|array|null $post Post data.
  64. */
  65. do_action( 'start_likes_meta_box_content', $post );
  66. ?>
  67. <p>
  68. <label for="wpl_enable_post_likes">
  69. <input type="checkbox" name="wpl_enable_post_likes" id="wpl_enable_post_likes" value="1" <?php checked( $checked ); ?>>
  70. <?php esc_html_e( 'Show likes.', 'jetpack' ); ?>
  71. </label>
  72. <input type="hidden" name="wpl_like_status_hidden" value="1" />
  73. </p> <?php
  74. /**
  75. * Fires after the Likes meta box content in the post editor.
  76. *
  77. * @module likes
  78. *
  79. * @since 2.2.0
  80. *
  81. * @param WP_Post|array|null $post Post data.
  82. */
  83. do_action( 'end_likes_meta_box_content', $post );
  84. }
  85. /**
  86. * Returns the current state of the "WordPress.com Likes are" option.
  87. * @return boolean true if enabled sitewide, false if not
  88. */
  89. public function is_enabled_sitewide() {
  90. /**
  91. * Filters whether Likes are enabled by default on all posts.
  92. * true if enabled sitewide, false if not.
  93. *
  94. * @module likes
  95. *
  96. * @since 2.2.0
  97. *
  98. * @param bool $option Are Likes enabled sitewide.
  99. */
  100. return (bool) apply_filters( 'wpl_is_enabled_sitewide', ! Jetpack_Options::get_option_and_ensure_autoload( 'disabled_likes', 0 ) );
  101. }
  102. public function meta_box_save( $post_id ) {
  103. if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
  104. return $post_id;
  105. }
  106. if ( empty( $_POST['wpl_like_status_hidden'] ) ) {
  107. return $post_id;
  108. }
  109. // Record sharing disable. Only needs to be done for WPCOM
  110. if ( ! $this->in_jetpack ) {
  111. if ( isset( $_POST['post_type'] ) && in_array( $_POST['post_type'], get_post_types( array( 'public' => true ) ) ) ) {
  112. if ( ! isset( $_POST['wpl_enable_post_sharing'] ) ) {
  113. update_post_meta( $post_id, 'sharing_disabled', 1 );
  114. } else {
  115. delete_post_meta( $post_id, 'sharing_disabled' );
  116. }
  117. }
  118. }
  119. if ( 'post' == $_POST['post_type'] ) {
  120. if ( !current_user_can( 'edit_post', $post_id ) ) {
  121. return $post_id;
  122. }
  123. }
  124. // Record a change in like status for this post - only if it contradicts the
  125. // site like setting. If it doesn't contradict, then we delete the new individual status.
  126. if ( ! $this->is_enabled_sitewide() && ! empty( $_POST['wpl_enable_post_likes'] ) ) {
  127. // Likes turned on for individual posts. User wants to add the button to a single post
  128. update_post_meta( $post_id, 'switch_like_status', 1 );
  129. } else if ( $this->is_enabled_sitewide() && empty( $_POST['wpl_enable_post_likes'] ) ) {
  130. // Likes turned on for all posts. User wants to remove the button from a single post
  131. update_post_meta( $post_id, 'switch_like_status', 0 );
  132. } else if (
  133. ( ! $this->is_enabled_sitewide() && empty( $_POST['wpl_enable_post_likes'] ) ) ||
  134. ( $this->is_enabled_sitewide() && ! empty( $_POST['wpl_enable_post_likes'] ) )
  135. ) {
  136. // User wants to update the likes button status for an individual post, but the new status
  137. // is the same as if they're asking for the default behaviour according to the current Likes setting.
  138. // So we delete the meta.
  139. delete_post_meta( $post_id, 'switch_like_status' );
  140. }
  141. return $post_id;
  142. }
  143. /**
  144. * WordPress.com: Metabox option for sharing (sharedaddy will handle this on the JP blog)
  145. */
  146. public function sharing_meta_box_content( $post ) {
  147. $post_id = ! empty( $post->ID ) ? (int) $post->ID : get_the_ID();
  148. $disabled = get_post_meta( $post_id, 'sharing_disabled', true ); ?>
  149. <p>
  150. <label for="wpl_enable_post_sharing">
  151. <input type="checkbox" name="wpl_enable_post_sharing" id="wpl_enable_post_sharing" value="1" <?php checked( !$disabled ); ?>>
  152. <?php _e( 'Show sharing buttons.', 'jetpack' ); ?>
  153. </label>
  154. <input type="hidden" name="wpl_sharing_status_hidden" value="1" />
  155. </p> <?php
  156. }
  157. /**
  158. * Adds the 'sharing' menu to the settings menu.
  159. * Only ran if sharedaddy and publicize are not already active.
  160. */
  161. function sharing_menu() {
  162. add_submenu_page( 'options-general.php', esc_html__( 'Sharing Settings', 'jetpack' ), esc_html__( 'Sharing', 'jetpack' ), 'manage_options', 'sharing', array( $this, 'sharing_page' ) );
  163. }
  164. /**
  165. * Provides a sharing page with the sharing_global_options hook
  166. * so we can display the setting.
  167. * Only ran if sharedaddy and publicize are not already active.
  168. */
  169. function sharing_page() {
  170. $this->updated_message(); ?>
  171. <div class="wrap">
  172. <div class="icon32" id="icon-options-general"><br /></div>
  173. <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1>
  174. <?php
  175. /** This action is documented in modules/sharedaddy/sharing.php */
  176. do_action( 'pre_admin_screen_sharing' );
  177. ?>
  178. <?php $this->sharing_block(); ?>
  179. </div> <?php
  180. }
  181. /**
  182. * Returns the settings have been saved message.
  183. */
  184. function updated_message() {
  185. if ( isset( $_GET['update'] ) && $_GET['update'] == 'saved' ){
  186. echo '<div class="updated"><p>' . esc_html__( 'Settings have been saved', 'jetpack' ) . '</p></div>';
  187. }
  188. }
  189. /**
  190. * Returns just the "sharing buttons" w/ like option block, so it can be inserted into different sharing page contexts
  191. */
  192. function sharing_block() { ?>
  193. <h2><?php esc_html_e( 'Sharing Buttons', 'jetpack' ); ?></h2>
  194. <form method="post" action="">
  195. <table class="form-table">
  196. <tbody>
  197. <?php
  198. /** This action is documented in modules/sharedaddy/sharing.php */
  199. do_action( 'sharing_global_options' );
  200. ?>
  201. </tbody>
  202. </table>
  203. <p class="submit">
  204. <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'jetpack' ); ?>" />
  205. </p>
  206. <input type="hidden" name="_wpnonce" value="<?php echo wp_create_nonce( 'sharing-options' );?>" />
  207. </form> <?php
  208. }
  209. /**
  210. * Are likes enabled for this post?
  211. *
  212. * @param int $post_id
  213. * @return bool
  214. */
  215. function is_post_likeable( $post_id = 0 ) {
  216. $post = get_post( $post_id );
  217. if ( !$post || is_wp_error( $post ) ) {
  218. return false;
  219. }
  220. $sitewide_likes_enabled = (bool) $this->is_enabled_sitewide();
  221. $post_likes_switched = get_post_meta( $post->ID, 'switch_like_status', true );
  222. return $post_likes_switched || ( $sitewide_likes_enabled && $post_likes_switched !== '0' );
  223. }
  224. /**
  225. * Are likes visible in this context?
  226. *
  227. * Some of this code was taken and modified from sharing_display() to ensure
  228. * similar logic and filters apply here, too.
  229. */
  230. function is_likes_visible() {
  231. require_once JETPACK__PLUGIN_DIR . '/sync/class.jetpack-sync-settings.php';
  232. if ( Jetpack_Sync_Settings::is_syncing() ) {
  233. return false;
  234. }
  235. global $wp_current_filter; // Used to apply 'sharing_show' filter
  236. $post = get_post();
  237. // Never show on feeds or previews
  238. if ( is_feed() || is_preview() ) {
  239. $enabled = false;
  240. // Not a feed or preview, so what is it?
  241. } else {
  242. if ( in_the_loop() ) {
  243. // If in the loop, check if the current post is likeable
  244. $enabled = $this->is_post_likeable();
  245. } else {
  246. // Otherwise, check and see if likes are enabled sitewide
  247. $enabled = $this->is_enabled_sitewide();
  248. }
  249. if ( post_password_required() )
  250. $enabled = false;
  251. if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) {
  252. $enabled = false;
  253. }
  254. // Sharing Setting Overrides ****************************************
  255. // Single post including custom post types
  256. if ( is_single() ) {
  257. if ( ! $this->is_single_post_enabled( $post->post_type ) ) {
  258. $enabled = false;
  259. }
  260. // Single page
  261. } elseif ( is_page() && ! is_front_page() ) {
  262. if ( ! $this->is_single_page_enabled() ) {
  263. $enabled = false;
  264. }
  265. // Attachment
  266. } elseif ( is_attachment() ) {
  267. if ( ! $this->is_attachment_enabled() ) {
  268. $enabled = false;
  269. }
  270. // All other loops
  271. } elseif ( ! $this->is_index_enabled() ) {
  272. $enabled = false;
  273. }
  274. }
  275. if ( $post instanceof WP_Post ) {
  276. // Check that the post is a public, published post.
  277. if ( 'attachment' == $post->post_type ) {
  278. $post_status = get_post_status( $post->post_parent );
  279. } else {
  280. $post_status = $post->post_status;
  281. }
  282. if ( 'publish' != $post_status ) {
  283. $enabled = false;
  284. }
  285. }
  286. // Run through the sharing filters
  287. /** This filter is documented in modules/sharedaddy/sharing-service.php */
  288. $enabled = apply_filters( 'sharing_show', $enabled, $post );
  289. /**
  290. * Filters whether the Likes should be visible or not.
  291. * Allows overwriting the options set in Settings > Sharing.
  292. *
  293. * @module likes
  294. *
  295. * @since 2.2.0
  296. *
  297. * @param bool $enabled Should the Likes be visible?
  298. */
  299. return (bool) apply_filters( 'wpl_is_likes_visible', $enabled );
  300. }
  301. /**
  302. * Are Post Likes enabled on single posts?
  303. *
  304. * @param String $post_type custom post type identifier
  305. * @return bool
  306. */
  307. function is_single_post_enabled( $post_type = 'post' ) {
  308. $options = $this->get_options();
  309. return (bool) apply_filters(
  310. /**
  311. * Filters whether Likes should be enabled on single posts.
  312. *
  313. * The dynamic part of the filter, {$post_type}, allows you to specific the post type where Likes should be enabled.
  314. *
  315. * @module likes
  316. *
  317. * @since 2.2.0
  318. *
  319. * @param bool $enabled Are Post Likes enabled on single posts?
  320. */
  321. "wpl_is_single_{$post_type}_disabled",
  322. (bool) in_array( $post_type, $options['show'] )
  323. );
  324. }
  325. /**
  326. * Get the 'disabled_likes' option from the DB of the current blog.
  327. *
  328. * @return array
  329. */
  330. function get_options() {
  331. $setting = array();
  332. $setting['disabled'] = get_option( 'disabled_likes' );
  333. $sharing = get_option( 'sharing-options' );
  334. // Default visibility settings
  335. if ( ! isset( $sharing['global']['show'] ) ) {
  336. $sharing['global']['show'] = array( 'post', 'page' );
  337. // Scalar check
  338. } elseif ( is_scalar( $sharing['global']['show'] ) ) {
  339. switch ( $sharing['global']['show'] ) {
  340. case 'posts' :
  341. $sharing['global']['show'] = array( 'post', 'page' );
  342. break;
  343. case 'index' :
  344. $sharing['global']['show'] = array( 'index' );
  345. break;
  346. case 'posts-index' :
  347. $sharing['global']['show'] = array( 'post', 'page', 'index' );
  348. break;
  349. }
  350. }
  351. // Ensure it's always an array (even if not previously empty or scalar)
  352. $setting['show'] = !empty( $sharing['global']['show'] ) ? (array) $sharing['global']['show'] : array();
  353. /**
  354. * Filters where the Likes are displayed.
  355. *
  356. * @module likes
  357. *
  358. * @since 2.2.0
  359. *
  360. * @param array $setting Array of Likes display settings.
  361. */
  362. return apply_filters( 'wpl_get_options', $setting );
  363. }
  364. /**
  365. * Are Post Likes enabled on archive/front/search pages?
  366. *
  367. * @return bool
  368. */
  369. function is_index_enabled() {
  370. $options = $this->get_options();
  371. /**
  372. * Filters whether Likes should be enabled on archive/front/search pages.
  373. *
  374. * @module likes
  375. *
  376. * @since 2.2.0
  377. *
  378. * @param bool $enabled Are Post Likes enabled on archive/front/search pages?
  379. */
  380. return (bool) apply_filters( 'wpl_is_index_disabled', (bool) in_array( 'index', $options['show'] ) );
  381. }
  382. /**
  383. * Are Post Likes enabled on single pages?
  384. *
  385. * @return bool
  386. */
  387. function is_single_page_enabled() {
  388. $options = $this->get_options();
  389. /**
  390. * Filters whether Likes should be enabled on single pages.
  391. *
  392. * @module likes
  393. *
  394. * @since 2.2.0
  395. *
  396. * @param bool $enabled Are Post Likes enabled on single pages?
  397. */
  398. return (bool) apply_filters( 'wpl_is_single_page_disabled', (bool) in_array( 'page', $options['show'] ) );
  399. }
  400. /**
  401. * Are Media Likes enabled on single pages?
  402. *
  403. * @return bool
  404. */
  405. function is_attachment_enabled() {
  406. $options = $this->get_options();
  407. /**
  408. * Filters whether Likes should be enabled on attachment pages.
  409. *
  410. * @module likes
  411. *
  412. * @since 2.2.0
  413. *
  414. * @param bool $enabled Are Post Likes enabled on attachment pages?
  415. */
  416. return (bool) apply_filters( 'wpl_is_attachment_disabled', (bool) in_array( 'attachment', $options['show'] ) );
  417. }
  418. /**
  419. * The actual options block to be inserted into the sharing page.
  420. */
  421. function admin_settings_init() {
  422. ?>
  423. <tr>
  424. <th scope="row">
  425. <label><?php esc_html_e( 'WordPress.com Likes are', 'jetpack' ); ?></label>
  426. </th>
  427. <td>
  428. <div>
  429. <label>
  430. <input type="radio" class="code" name="wpl_default" value="on" <?php checked( $this->is_enabled_sitewide(), true ); ?> />
  431. <?php esc_html_e( 'On for all posts', 'jetpack' ); ?>
  432. </label>
  433. </div>
  434. <div>
  435. <label>
  436. <input type="radio" class="code" name="wpl_default" value="off" <?php checked( $this->is_enabled_sitewide(), false ); ?> />
  437. <?php esc_html_e( 'Turned on per post', 'jetpack' ); ?>
  438. </label>
  439. <div>
  440. </td>
  441. </tr>
  442. <?php if ( ! $this->in_jetpack ) : ?>
  443. <tr>
  444. <th scope="row">
  445. <label><?php esc_html_e( 'WordPress.com Reblog Button', 'jetpack' ); ?></label>
  446. </th>
  447. <td>
  448. <div>
  449. <label>
  450. <input type="radio" class="code" name="jetpack_reblogs_enabled" value="on" <?php checked( $this->reblogs_enabled_sitewide(), true ); ?> />
  451. <?php esc_html_e( 'Show the Reblog button on posts', 'jetpack' ); ?>
  452. </label>
  453. </div>
  454. <div>
  455. <label>
  456. <input type="radio" class="code" name="jetpack_reblogs_enabled" value="off" <?php checked( $this->reblogs_enabled_sitewide(), false ); ?> />
  457. <?php esc_html_e( 'Don\'t show the Reblog button on posts', 'jetpack' ); ?>
  458. </label>
  459. <div>
  460. </td>
  461. </tr>
  462. <?php endif; ?>
  463. </tbody> <?php // closes the tbody attached to sharing_show_buttons_on_row_start... ?>
  464. <?php
  465. }
  466. /**
  467. * Returns the current state of the "WordPress.com Reblogs are" option.
  468. * @return boolean true if enabled sitewide, false if not
  469. */
  470. function reblogs_enabled_sitewide() {
  471. /**
  472. * Filters whether Reblogs are enabled by default on all posts.
  473. * true if enabled sitewide, false if not.
  474. *
  475. * @module likes
  476. *
  477. * @since 3.0.0
  478. *
  479. * @param bool $option Are Reblogs enabled sitewide.
  480. */
  481. return (bool) apply_filters( 'wpl_reblogging_enabled_sitewide', ! get_option( 'disabled_reblogs' ) );
  482. }
  483. /**
  484. * Saves the setting in the database, bumps a stat on WordPress.com
  485. */
  486. function admin_settings_callback() {
  487. // We're looking for these, and doing a dance to set some stats and save
  488. // them together in array option.
  489. $new_state = !empty( $_POST['wpl_default'] ) ? $_POST['wpl_default'] : 'on';
  490. $db_state = $this->is_enabled_sitewide();
  491. $reblogs_new_state = !empty( $_POST['jetpack_reblogs_enabled'] ) ? $_POST['jetpack_reblogs_enabled'] : 'on';
  492. $reblogs_db_state = $this->reblogs_enabled_sitewide();
  493. /** Default State *********************************************************/
  494. // Checked (enabled)
  495. switch( $new_state ) {
  496. case 'off' :
  497. if ( true == $db_state && ! $this->in_jetpack ) {
  498. $g_gif = file_get_contents( 'https://pixel.wp.com/g.gif?v=wpcom-no-pv&x_likes=disabled_likes' );
  499. }
  500. update_option( 'disabled_likes', 1 );
  501. break;
  502. case 'on' :
  503. default:
  504. if ( false == $db_state && ! $this->in_jetpack ) {
  505. $g_gif = file_get_contents( 'https://pixel.wp.com/g.gif?v=wpcom-no-pv&x_likes=reenabled_likes' );
  506. }
  507. delete_option( 'disabled_likes' );
  508. break;
  509. }
  510. switch( $reblogs_new_state ) {
  511. case 'off' :
  512. if ( true == $reblogs_db_state && ! $this->in_jetpack ) {
  513. $g_gif = file_get_contents( 'https://pixel.wp.com/g.gif?v=wpcom-no-pv&x_reblogs=disabled_reblogs' );
  514. }
  515. update_option( 'disabled_reblogs', 1 );
  516. break;
  517. case 'on' :
  518. default:
  519. if ( false == $reblogs_db_state && ! $this->in_jetpack ) {
  520. $g_gif = file_get_contents( 'https://pixel.wp.com/g.gif?v=wpcom-no-pv&x_reblogs=reenabled_reblogs' );
  521. }
  522. delete_option( 'disabled_reblogs' );
  523. break;
  524. }
  525. }
  526. /**
  527. * Adds the admin update hook so we can save settings even if Sharedaddy is not enabled.
  528. */
  529. function process_update_requests_if_sharedaddy_not_loaded() {
  530. if ( isset( $_GET['page'] ) && ( $_GET['page'] == 'sharing.php' || $_GET['page'] == 'sharing' ) ) {
  531. if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( $_POST['_wpnonce'], 'sharing-options' ) ) {
  532. /** This action is documented in modules/sharedaddy/sharing.php */
  533. do_action( 'sharing_admin_update' );
  534. wp_safe_redirect( admin_url( 'options-general.php?page=sharing&update=saved' ) );
  535. die();
  536. }
  537. }
  538. }
  539. /**
  540. * If sharedaddy is not loaded, we don't have the "Show buttons on" yet, so we need to add that since it affects likes too.
  541. */
  542. function admin_settings_showbuttonon_init() {
  543. ?>
  544. <?php
  545. /** This action is documented in modules/sharedaddy/sharing.php */
  546. echo apply_filters( 'sharing_show_buttons_on_row_start', '<tr valign="top">' );
  547. ?>
  548. <th scope="row"><label><?php _e( 'Show buttons on', 'jetpack' ); ?></label></th>
  549. <td>
  550. <?php
  551. $br = false;
  552. $shows = array_values( get_post_types( array( 'public' => true ) ) );
  553. array_unshift( $shows, 'index' );
  554. $global = $this->get_options();
  555. foreach ( $shows as $show ) :
  556. if ( 'index' == $show ) {
  557. $label = __( 'Front Page, Archive Pages, and Search Results', 'jetpack' );
  558. } else {
  559. $post_type_object = get_post_type_object( $show );
  560. $label = $post_type_object->labels->name;
  561. }
  562. ?>
  563. <?php if ( $br ) echo '<br />'; ?><label><input type="checkbox"<?php checked( in_array( $show, $global['show'] ) ); ?> name="show[]" value="<?php echo esc_attr( $show ); ?>" /> <?php echo esc_html( $label ); ?></label>
  564. <?php $br = true; endforeach; ?>
  565. </td>
  566. <?php
  567. /** This action is documented in modules/sharedaddy/sharing.php */
  568. echo apply_filters( 'sharing_show_buttons_on_row_end', '</tr>' );
  569. ?>
  570. <?php
  571. }
  572. /**
  573. * If sharedaddy is not loaded, we still need to save the the settings of the "Show buttons on" option.
  574. */
  575. function admin_settings_showbuttonon_callback() {
  576. $options = get_option( 'sharing-options' );
  577. if ( !is_array( $options ) )
  578. $options = array();
  579. $shows = array_values( get_post_types( array( 'public' => true ) ) );
  580. $shows[] = 'index';
  581. $data = $_POST;
  582. if ( isset( $data['show'] ) ) {
  583. if ( is_scalar( $data['show'] ) ) {
  584. switch ( $data['show'] ) {
  585. case 'posts' :
  586. $data['show'] = array( 'post', 'page' );
  587. break;
  588. case 'index' :
  589. $data['show'] = array( 'index' );
  590. break;
  591. case 'posts-index' :
  592. $data['show'] = array( 'post', 'page', 'index' );
  593. break;
  594. }
  595. }
  596. if ( $data['show'] = array_intersect( $data['show'], $shows ) ) {
  597. $options['global']['show'] = $data['show'];
  598. }
  599. } else {
  600. $options['global']['show'] = array();
  601. }
  602. update_option( 'sharing-options', $options );
  603. }
  604. }