DB_Twitter_Feed_Main_Options

The WordPress Core DB Twitter Feed Main Options class.

Defined (1)

The class is defined in the following location(s).

/admin/class.main-options.php  
  1. class DB_Twitter_Feed_Main_Options extends DB_Plugin_WP_Admin_Helper { 
  2.  
  3. /** 
  4. * @var array Holds important information about sections on the settings page 
  5. * @since 1.0.0 
  6. */ 
  7. private $sections = array(); 
  8.  
  9. /** 
  10. * @var array Holds important information about individual settings on the settings page 
  11. * @since 1.0.0 
  12. */ 
  13. private $settings = array(); 
  14.  
  15. /** 
  16. * @var string The prefix used to ensure that the IDs of HTML items are unique to the plugin 
  17. * @since 2.0.0 
  18. */ 
  19. protected $html_item_id_prefix; 
  20.  
  21.  
  22. /** 
  23. * Sets up the settings and initialises them within WordPress 
  24. * @access public 
  25. * @return void 
  26. * @since 1.0.0 
  27. */ 
  28. public function __construct() { 
  29. $this->set_main_admin_vars(); 
  30.  
  31. $this->html_item_id_prefix = $this->plugin_short_name.'_'; 
  32.  
  33. $this->set_sections(); 
  34. $this->set_settings(); 
  35.  
  36. add_action( 'admin_menu', array( $this, 'add_menu_item' ) ); 
  37. add_action( 'admin_init', array( $this, 'init_options' ) ); 
  38. add_action( 'admin_head', array( $this, 'set_admin_vars_js' ) ); 
  39. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_styles' ) ); 
  40.  
  41.  
  42. /** 
  43. * Establish the details of the sections to be rendered by WP on this settings page 
  44. * @access private 
  45. * @return void 
  46. * @since 1.0.0 
  47. */ 
  48. private function set_sections() { 
  49. $this->sections = 
  50. array( 
  51. 'cache' => array( 
  52. 'id' => 'cache_sec',  
  53. 'title' => 'Cache Management',  
  54. 'callback' => array( $this, 'write_cache_sec' ),  
  55. 'page' => $this->page_uri_main 
  56. ),  
  57. 'config' => array( 
  58. 'id' => 'configuration_sec',  
  59. 'title' => 'Configuration',  
  60. 'callback' => array( $this, 'write_configuration_sec' ),  
  61. 'page' => $this->page_uri_main 
  62. ),  
  63. 'feed' => array( 
  64. 'id' => 'feed_sec',  
  65. 'title' => 'Feed Settings',  
  66. 'callback' => array( $this, 'write_feed_sec' ),  
  67. 'page' => $this->page_uri_main 
  68. ),  
  69. 'settings' => array( 
  70. 'id' => 'settings_sec',  
  71. 'title' => 'General Settings',  
  72. 'callback' => array( $this, 'write_settings_sec' ),  
  73. 'page' => $this->page_uri_main 
  74. ); 
  75.  
  76.  
  77. /** 
  78. * Establish the details of the settings to be rendered by WP on this settings page 
  79. * @access private 
  80. * @return void 
  81. * @since 1.0.0 
  82. */ 
  83. private function set_settings() { 
  84. $this->settings = 
  85. array( 
  86. 'consumer_key' => array( 
  87. 'id' => 'consumer_key',  
  88. 'title' => 'Consumer Key',  
  89. 'callback' => array( $this, 'write_consumer_key_field' ),  
  90. 'page' => $this->page_uri_main,  
  91. 'section' => 'configuration_sec',  
  92. 'args' => '' 
  93. ),  
  94. 'consumer_secret' => array( 
  95. 'id' => 'consumer_secret',  
  96. 'title' => 'Consumer Secret',  
  97. 'callback' => array( $this, 'write_consumer_secret_field' ),  
  98. 'page' => $this->page_uri_main,  
  99. 'section' => 'configuration_sec',  
  100. 'args' => '' 
  101. ),  
  102. 'oauth_access_token' => array( 
  103. 'id' => 'oauth_access_token',  
  104. 'title' => 'OAuth Access Token',  
  105. 'callback' => array( $this, 'write_oauth_access_token_field' ),  
  106. 'page' => $this->page_uri_main,  
  107. 'section' => 'configuration_sec',  
  108. 'args' => '' 
  109. ),  
  110. 'oauth_access_token_secret' => array( 
  111. 'id' => 'oauth_access_token_secret',  
  112. 'title' => 'OAuth Access Token Secret',  
  113. 'callback' => array( $this, 'write_oauth_access_token_secret_field' ),  
  114. 'page' => $this->page_uri_main,  
  115. 'section' => 'configuration_sec',  
  116. 'args' => '' 
  117. ),  
  118. 'feed_type' => array( 
  119. 'id' => 'feed_type',  
  120. 'title' => 'Feed Type',  
  121. 'callback' => array( $this, 'write_radio_fields' ),  
  122. 'page' => $this->page_uri_main,  
  123. 'section' => 'feed_sec',  
  124. 'args' => array( 
  125. 'no_label' => TRUE,  
  126. 'options' => array( 
  127. 'Timeline' => 'user_timeline',  
  128. 'Search' => 'search' 
  129. ),  
  130. 'user' => array( 
  131. 'id' => 'twitter_username',  
  132. 'title' => 'Twitter Username',  
  133. 'callback' => array( $this, 'write_twitter_username_field' ),  
  134. 'page' => $this->page_uri_main,  
  135. 'section' => 'feed_sec',  
  136. 'args' => array( 
  137. 'attr' => array( 
  138. 'class' => 'input_feed_type' 
  139. ),  
  140. 'search_term' => array( 
  141. 'id' => 'search_term',  
  142. 'title' => 'Search Term',  
  143. 'callback' => array( $this, 'write_search_term_field' ),  
  144. 'page' => $this->page_uri_main,  
  145. 'section' => 'feed_sec',  
  146. 'args' => array( 
  147. 'desc' => 'Searches with or without a hashtag are acceptable.',  
  148. 'attr' => array( 
  149. 'class' => 'input_feed_type' 
  150. ),  
  151. 'result_count' => array( 
  152. 'id' => 'result_count',  
  153. 'title' => 'Number of tweets to show',  
  154. 'callback' => array( $this, 'write_numeric_dropdown_field' ),  
  155. 'page' => $this->page_uri_main,  
  156. 'section' => 'settings_sec',  
  157. 'args' => array( 
  158. 'min' => 1,  
  159. 'max' => 30 
  160. ),  
  161. 'cache_hours' => array( 
  162. 'id' => 'cache_hours',  
  163. 'title' => 'Cache the feed for how many hours?',  
  164. 'callback' => array( $this, 'write_numeric_dropdown_field' ),  
  165. 'page' => $this->page_uri_main,  
  166. 'section' => 'settings_sec',  
  167. 'args' => array( 
  168. 'min' => 0,  
  169. 'max' => 24,  
  170. 'desc' => '<p class="description">Select 0 if you don’t wish to cache the feed.</p>' ) 
  171. ),  
  172. 'exclude_replies' => array( 
  173. 'id' => 'exclude_replies',  
  174. 'title' => 'Exclude replies?',  
  175. 'callback' => array( $this, 'write_checkbox_field' ),  
  176. 'page' => $this->page_uri_main,  
  177. 'section' => 'settings_sec',  
  178. 'args' => array( 
  179. 'desc' => '<p class="description">Twitter removes replies only after it retrieves the number of tweets you request.<br />Thus if you choose 10, and out of that 10 6 are replies, only 4 tweets will be displayed.</p>' 
  180. ),  
  181. 'show_images' => array( 
  182. 'id' => 'show_images',  
  183. 'title' => 'Show embedded images?',  
  184. 'callback' => array( $this, 'write_checkbox_field' ),  
  185. 'page' => $this->page_uri_main,  
  186. 'section' => 'settings_sec',  
  187. 'args' => '' 
  188. ),  
  189. 'https' => array( 
  190. 'id' => 'https',  
  191. 'title' => 'Load media over HTTPS?',  
  192. 'callback' => array( $this, 'write_checkbox_field' ),  
  193. 'page' => $this->page_uri_main,  
  194. 'section' => 'settings_sec',  
  195. 'args' => array( 
  196. 'desc' => '<p class="description">This only affects media served by Twitter.</p>' 
  197. ),  
  198. 'default_styling' => array( 
  199. 'id' => 'default_styling',  
  200. 'title' => 'Load default stylesheet?',  
  201. 'callback' => array( $this, 'write_checkbox_field' ),  
  202. 'page' => $this->page_uri_main,  
  203. 'section' => 'settings_sec',  
  204. 'args' => '' 
  205. )/**,  
  206. '' => array( 
  207. 'id' => '',  
  208. 'title' => '',  
  209. 'callback' => array( $this, 'write__field' ),  
  210. 'page' => $this->page_uri_main,  
  211. 'section' => '',  
  212. 'args' => '' 
  213. )*/ 
  214. ); 
  215.  
  216. foreach ( $this->settings as $name => $setting ) { 
  217. $id = $setting['id']; 
  218. $title = $setting['title']; 
  219. $html_item_id = $this->html_item_id_prefix.$id; 
  220.  
  221. // Wrap title in label, add it to appropriate $settings property 
  222. $no_label = ( isset( $setting['args']['no_label'] ) ) ? $setting['args']['no_label'] : FALSE; 
  223. if ( $no_label !== TRUE ) { 
  224. $this->settings[ $name ]['title'] = '<label for="'.$html_item_id.'">'.$title.'</label>'; 
  225.  
  226.  
  227. // Add standard data to the arguments of the setting 
  228. if ( is_array( $setting['args'] ) ) { 
  229. $this->settings[ $name ]['args']['option'] = $id; 
  230. } else { 
  231. $this->settings[ $name ]['args'] = array( 'option' => $id ); 
  232.  
  233. $this->settings[ $name ]['args']['html_item_id'] = $html_item_id; 
  234.  
  235.  
  236.  
  237. /** 
  238. * Load JavaScripts and styles necessary for the page 
  239. * @access public 
  240. * @return void 
  241. * @since 2.0.0 
  242. */ 
  243. public function enqueue_scripts_styles( $hook ) { 
  244. if ( $hook != 'settings_page_db-twitter-feed-settings' ) { 
  245. return; 
  246. wp_enqueue_style( $this->plugin_name.'_admin_styles', DBTF_URL.'/assets/main-admin.css', NULL, '1.0.1', 'all' ); 
  247. wp_enqueue_script( $this->plugin_name.'_admin_functions', DBTF_URL.'/assets/main-admin.js', array( 'jquery-core' ), '1.0.0', true ); 
  248.  
  249.  
  250. /** 
  251. * Create global JavaScript object that will hold certain plugin information 
  252. * @access public 
  253. * @return void 
  254. * @since 2.0.0 
  255. */ 
  256. public function set_admin_vars_js() { 
  257. $br = "\n"; 
  258. $tab = ' '; 
  259.  
  260. $class_name = strtoupper($this->plugin_short_name); 
  261.  
  262. $output = $br.'<script type="text/javascript">'.$br; 
  263. $output .= $tab.'var '.$class_name.' = '.$class_name.' || {};'.$br; 
  264.  
  265. $output .= $tab.$class_name.'.pluginName = \''.$this->plugin_name.'\';'.$br; 
  266. $output .= $tab.$class_name.'.pluginShortName = \''.$this->plugin_short_name.'\';'.$br; 
  267.  
  268. $output .= $tab.$class_name.'.optionsNameMain = \''.$this->options_name_main.'\';'.$br; 
  269. $output .= $tab.$class_name.'.optionsGroup = \''.$this->options_group_main.'\';'.$br; 
  270.  
  271. $output .= '</script>'.$br.$br; 
  272.  
  273. echo $output; 
  274.  
  275.  
  276. /** 
  277. * Add the item to the WordPress admin menu and call the function that renders the markup 
  278. * @access public 
  279. * @return void 
  280. * @since 1.0.0 
  281. */ 
  282. public function add_menu_item() { 
  283. add_submenu_page( 
  284. 'options-general.php',  
  285. 'Configure your Twitter feed set up',  
  286. 'Twitter Feed Settings',  
  287. 'manage_options',  
  288. $this->page_uri_main,  
  289. array( $this, 'settings_page_markup' ) 
  290. ); 
  291.  
  292.  
  293. /** 
  294. * Officially register the sections/settings with WordPress 
  295. * @access public 
  296. * @return void 
  297. * @since 1.0.0 
  298. */ 
  299. public function init_options() { 
  300. register_setting( $this->options_group_main, $this->options_name_main, array( $this, 'sanitize_settings_submission' ) ); 
  301.  
  302. // Loop through the Sections/Settings arrays and add them to WordPress 
  303. foreach ( $this->sections as $section ) { 
  304. add_settings_section( 
  305. $section['id'],  
  306. $section['title'],  
  307. $section['callback'],  
  308. $section['page'] 
  309. ); 
  310. foreach ( $this->settings as $setting ) { 
  311. add_settings_field( 
  312. $setting['id'],  
  313. $setting['title'],  
  314. $setting['callback'],  
  315. $setting['page'],  
  316. $setting['section'],  
  317. $setting['args'] 
  318. ); 
  319.  
  320.  
  321. /************************************************************************************************************** 
  322. Callbacks for writing the option fields themselves to the options page 
  323. **************************************************************************************************************/ 
  324. /** 
  325. * Write the markup for the settings page 
  326. * This method also checks to see if settings have been updated. If they have 
  327. * the method will clear the cache of the ID currently in the twitter_username 
  328. * field. 
  329. * @access public 
  330. * @return void 
  331. * @since 1.0.0 
  332. */ 
  333. public function settings_page_markup() { 
  334. if ( ! current_user_can( 'manage_options' ) ) { 
  335. wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); 
  336. } ?> 
  337.  
  338. <div id="<?php echo $this->plugin_short_name ?>" class="wrap"> 
  339.  
  340. <?php screen_icon() ?> 
  341. <h2>Twitter Feed Settings</h2> 
  342.  
  343. <form id="<?php echo $this->plugin_name ?>_settings" action="options.php" method="post"> 
  344. <?php 
  345. settings_fields( $this->options_group_main ); 
  346. do_settings_sections( $this->page_uri_main ); 
  347.  
  348. submit_button( 'Save Changes' ) 
  349. ?> 
  350. </form> 
  351.  
  352. </div><!--END-<?php echo $this->plugin_short_name ?>--> 
  353. <?php } 
  354.  
  355.  
  356. /** 
  357. * Takes a string and returns it with the plugin's shortname prefixed to it 
  358. * This method should only be used to prefix HTML 
  359. * id attributes 
  360. * @access protected 
  361. * @return string 
  362. * @since 2.0.0 
  363. * @param string $item_id The ID of the item to be prefixed 
  364. */ 
  365. protected function _html_item_id_attr( $item_id ) { 
  366. return $this->html_item_id_prefix.$item_id; 
  367.  
  368.  
  369. /** Write Cache Management section 
  370. *******************************************/ 
  371. /** 
  372. * Output the Cache management section and its fields 
  373. * @access public 
  374. * @return void 
  375. * @since 2.0.0 
  376. */ 
  377. public function write_cache_sec() { 
  378. echo 'Select a cache segment to clear.'; 
  379. echo '<div class="' . $this->plugin_short_name . '_cache_management_section settings_item">'; 
  380.  
  381. echo '<select name="' . $this->options_name_main . '[cache_segment]" id="' . $this->plugin_short_name . '_cache_segment"> 
  382. <option value="0">--</option> 
  383. <option value="user_timeline">User timelines</option> 
  384. <option value="search">Searches</option> 
  385. <option value="all">All</option> 
  386. </select>'; 
  387.  
  388. echo '<input type="hidden" id="' . $this->plugin_short_name . '_cache_clear_flag" name="' . $this->options_name_main . '[cache_clear_flag]" value="0" />'; 
  389.  
  390. echo get_submit_button( 'Clear Cache', 'secondary', $this->plugin_short_name . '_batch_clear_cache' ); 
  391. echo '</div>'; 
  392.  
  393.  
  394. /** 
  395. * Output batch clear cache field 
  396. * @access public 
  397. * @return void 
  398. * @since 2.0.0 
  399. */ 
  400. public function write_cache_segment_field() { 
  401. echo ''; 
  402.  
  403.  
  404. /** 
  405. * Output batch clear clear flag field 
  406. * @access public 
  407. * @return void 
  408. * @since 2.0.0 
  409. */ 
  410. public function write_cache_clear_flag() { 
  411. echo ''; 
  412.  
  413.  
  414. /** Write Configuration section 
  415. *******************************************/ 
  416. /** 
  417. * Output the section as set in the set_sections() method along with a little bit of guidance 
  418. * @access public 
  419. * @return void 
  420. * @since 1.0.0 
  421. */ 
  422. public function write_configuration_sec() { 
  423. echo 'You\'ll need to log into the Twitter Developers site and set up an app. Once you\'ve set one up you will get the data necessary for below. For a step by step, see the <a href="http://wordpress.org/plugins/devbuddy-twitter-feed/installation/" target="_blank">walkthrough</a>.'; 
  424.  
  425.  
  426. /** 
  427. * Output the Consumer Key setting's field 
  428. * @access public 
  429. * @return void 
  430. * @since 1.0.0 
  431. */ 
  432. public function write_consumer_key_field( $args ) { 
  433. $consumer_key = $this->get_db_plugin_option( $this->options_name_main, 'consumer_key' ); 
  434. $consumer_key = $this->mask_data( $consumer_key ); 
  435.  
  436. echo '<input type="text" id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'[consumer_key]" value="'.$consumer_key.'" style="width:450px;" />'; 
  437.  
  438.  
  439. /** 
  440. * Output the Consumer Secret setting's field 
  441. * @access public 
  442. * @return void 
  443. * @since 1.0.0 
  444. */ 
  445. public function write_consumer_secret_field( $args ) { 
  446. $consumer_secret = $this->get_db_plugin_option( $this->options_name_main, 'consumer_secret' ); 
  447. $consumer_secret = $this->mask_data( $consumer_secret ); 
  448.  
  449. echo '<input type="text" id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'[consumer_secret]" value="'.$consumer_secret.'" style="width:450px;" />'; 
  450.  
  451.  
  452. /** 
  453. * Output the OAuth Access Token setting's field 
  454. * @access public 
  455. * @return void 
  456. * @since 1.0.0 
  457. */ 
  458. public function write_oauth_access_token_field( $args ) { 
  459. $oauth_access_token = $this->get_db_plugin_option( $this->options_name_main, 'oauth_access_token' ); 
  460.  
  461. $oat_arr = explode( '-', $oauth_access_token ); 
  462. $start = strlen( $oat_arr[0] ); 
  463.  
  464. $oauth_access_token = $this->mask_data( $oauth_access_token, $start ); 
  465.  
  466. echo '<input type="text" id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'[oauth_access_token]" value="'.$oauth_access_token.'" style="width:450px;" />'; 
  467.  
  468.  
  469. /** 
  470. * Output the OAuth Access Token Secret setting's field 
  471. * @access public 
  472. * @return void 
  473. * @since 1.0.0 
  474. */ 
  475. public function write_oauth_access_token_secret_field( $args ) { 
  476. $oauth_access_token_secret = $this->get_db_plugin_option( $this->options_name_main, 'oauth_access_token_secret' ); 
  477. $oauth_access_token_secret = $this->mask_data( $oauth_access_token_secret ); 
  478.  
  479. echo '<input type="text" id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'[oauth_access_token_secret]" value="'.$oauth_access_token_secret.'" style="width:450px;" />'; 
  480.  
  481.  
  482. /** Write Feed Settings section 
  483. *******************************************/ 
  484. /** 
  485. * Output the section as set in the set_sections() method 
  486. * @access public 
  487. * @return void 
  488. * @since 1.0.0 
  489. */ 
  490. public function write_feed_sec() { 
  491. echo ''; 
  492.  
  493.  
  494. /** 
  495. * Output the Twitter username setting's field 
  496. * @access public 
  497. * @return void 
  498. * @since 1.0.0 
  499. */ 
  500. public function write_twitter_username_field( $args ) { 
  501. $twitter_username = $this->get_db_plugin_option( $this->options_name_main, 'twitter_username' ); 
  502.  
  503. echo '<strong>twitter.com/<input type="text" id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'[twitter_username]"'; 
  504.  
  505. if ( $twitter_username ) { 
  506. echo ' value="'.$twitter_username.'"'; 
  507.  
  508. echo ( isset( $args['attr'] ) ) ? $this->write_attr( $args['attr'] ) : ''; 
  509.  
  510. echo ' /></strong>'; 
  511.  
  512. echo '<input type="hidden" name="'.$this->options_name_main.'[twitter_username_hid]"'; 
  513.  
  514. if ( $twitter_username ) { 
  515. echo ' value="'.$twitter_username.'"'; 
  516.  
  517. echo ' />'; 
  518.  
  519. echo ( isset( $args['desc'] ) ) ? $this->write_desc( $args['desc'] ) : ''; 
  520.  
  521.  
  522. /** 
  523. * Output the Twitter username setting's field 
  524. * @access public 
  525. * @return void 
  526. * @since 1.0.0 
  527. */ 
  528. public function write_search_term_field( $args ) { 
  529. $search_term = $this->get_db_plugin_option( $this->options_name_main, 'search_term' ); 
  530.  
  531. echo '<input type="text" id="'.$this->_html_item_id_attr( $args['option'] ).'" name="'.$this->options_name_main.'[search_term]"'; 
  532.  
  533. if ( $search_term ) { 
  534. echo ' value="'.$search_term.'"'; 
  535.  
  536. echo ( isset( $args['attr'] ) ) ? $this->write_attr( $args['attr'] ) : ''; 
  537.  
  538. echo ' />'; 
  539.  
  540. echo '<input type="hidden" name="'.$this->options_name_main.'[search_term_hid]"'; 
  541.  
  542. if ( $search_term ) { 
  543. echo ' value="'.$search_term.'"'; 
  544.  
  545. echo ' />'; 
  546.  
  547. echo ( isset( $args['desc'] ) ) ? $this->write_desc( $args['desc'] ) : ''; 
  548.  
  549.  
  550. /** Write General Settings section 
  551. *******************************************/ 
  552. /** 
  553. * Output the section as set in the set_sections() method 
  554. * @access public 
  555. * @return void 
  556. * @since 1.0.0 
  557. */ 
  558. public function write_settings_sec() { 
  559. echo ''; 
  560.  
  561. }// END class