/admin/init.php

  1. <?php 
  2. /**-----------------------------------------------------------------------------------*/ 
  3. /* Init settings - Options variable & functions 
  4. /**-----------------------------------------------------------------------------------*/ 
  5.  
  6. // General options 
  7. function gl_get_general_settings_key( ) { 
  8. return 'g_locker_general_settings'; 
  9.  
  10. function gl_get_general_settings_values( ) { 
  11. $general_settings = (array) get_option( gl_get_general_settings_key() ); 
  12.  
  13. // Merge with general defaults 
  14. $general_settings = array_merge( gl_general_default_settings(), $general_settings ); 
  15.  
  16. return $general_settings; 
  17.  
  18. // Social options 
  19. function gl_get_social_lock_settings_key( ) { 
  20. return 'g_locker_social_lock_settings'; 
  21.  
  22. function gl_get_social_lock_setting_values( ) { 
  23. $social_lock_settings = (array) get_option( gl_get_social_lock_settings_key() ); 
  24.  
  25. // Merge with social defaults 
  26. $social_lock_settings = array_merge( gl_social_lock_default_settings(), $social_lock_settings ); 
  27.  
  28. return $social_lock_settings; 
  29.  
  30. // Content options 
  31. function gl_get_content_lock_settings_key( ) { 
  32. return 'g_locker_content_lock_settings'; 
  33.  
  34. function gl_get_content_lock_setting_values( ) { 
  35. $content_lock_settings = (array) get_option( gl_get_content_lock_settings_key() ); 
  36.  
  37. // Merge with content defaults 
  38. $content_lock_settings = array_merge( gl_content_lock_default_settings(), $content_lock_settings ); 
  39.  
  40. return $content_lock_settings; 
  41.  
  42. function gl_get_howtouse_settings_key( ) { 
  43. return 'g_locker_howtouse_settings'; 
  44.  
  45. function gl_get_plugin_options_key( ) { 
  46. return 'g_locker'; 
  47.  
  48. // Function get all settings tabs 
  49. function gl_get_plugin_settings_tabs( ) { 
  50. $plugin_settings_tabs[ gl_get_general_settings_key() ] = 'General'; 
  51. $plugin_settings_tabs[ gl_get_social_lock_settings_key() ] = 'Social Locker'; 
  52. $plugin_settings_tabs[ gl_get_content_lock_settings_key() ] = 'Content Locker'; 
  53. $plugin_settings_tabs[ gl_get_howtouse_settings_key() ] = 'How to use?'; 
  54.  
  55. return $plugin_settings_tabs; 
  56.  
  57. // General default options value 
  58. function gl_general_default_settings( ) { 
  59. $general_default_settings = array( 
  60. 'google_active' => '',  
  61. 'google_share' => '',  
  62. 'google_url' => 'http://www.wptp.net',  
  63. 'youtube_active' => '',  
  64. 'youtube_channel' => 'GoogleDevelopers',  
  65. 'language' => 'en_US',  
  66. 'short_language' => 'en',  
  67. 'cookie_days' => '365' 
  68. ); 
  69.  
  70. return $general_default_settings; 
  71.  
  72. // Social default options value 
  73. function gl_social_lock_default_settings( ) { 
  74. $social_lock_default_settings = array( 
  75. 'sl_title' => 'This content is locked!',  
  76. 'sl_message' => 'This is Google Locker. Please click on one of the buttons.',  
  77. 'sl_style' => 'starter',  
  78. 'sl_title_color' => '#000000',  
  79. 'sl_message_color' => '#000000',  
  80. 'sl_bg_color' => '#22d8d2',  
  81. 'sl_shadow_color' => '#22d8d2',  
  82. 'sl_layout' => 'count',  
  83. 'sl_btn_effect' => 'fade' 
  84. ); 
  85.  
  86. return $social_lock_default_settings; 
  87.  
  88. // Content default options value 
  89. function gl_content_lock_default_settings( ) { 
  90. $content_lock_default_settings = array( 
  91. 'cl_title' => 'This content is locked!',  
  92. 'cl_message' => 'This is Google Locker. Please click on one of the buttons.',  
  93. 'cl_style' => 'starter',  
  94. 'cl_title_color' => '#000000',  
  95. 'cl_message_color' => '#000000',  
  96. 'cl_bg_color' => '#22d8d2',  
  97. 'cl_shadow_color' => '#22d8d2',  
  98. 'cl_layout' => 'count',  
  99. 'cl_btn_effect' => 'fade' 
  100. ); 
  101.  
  102. return $content_lock_default_settings; 
  103.  
  104. function gl_init_settings( ) { 
  105. // Load jQuery First 
  106. wp_enqueue_script( 'jquery' ); 
  107.  
  108. // CSS 
  109. wp_deregister_style( 'gl_css' ); 
  110. wp_register_style( 'gl_css', G_LOCKER_PLUGIN_URL . '/assets/css/gl.css' ); 
  111. wp_enqueue_style( 'gl_css' ); 
  112.  
  113. // Show color picker for some color option. Example: Title Color, Shadow Color 
  114. if ( is_admin() ) { 
  115. // Jquery UI 
  116. wp_enqueue_script( 'jquery-ui', 'https://code.jquery.com/jquery-1.10.2.js'); 
  117. wp_enqueue_script( 'jquery-ui', 'https://code.jquery.com/ui/1.11.2/jquery-ui.js'); 
  118. wp_enqueue_style( 'jquery-ui', 'https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css' ); 
  119.  
  120. // Color Picker for color options 
  121. wp_enqueue_style( 'wp-color-picker' ); 
  122. wp_enqueue_script( 'gl-custom-script-handle', G_LOCKER_PLUGIN_URL . '/assets/js/gl-wp-color-picker.js', array( 
  123. 'wp-color-picker'  
  124. ), false, true ); 
  125.  
  126. add_action( 'init', 'gl_init_settings' ); 
  127.  
  128. /**-----------------------------------------------------------------------------------*/ 
  129. /* Short code 
  130. /**-----------------------------------------------------------------------------------*/ 
  131.  
  132. require_once( G_LOCKER_PLUGIN_DIR . '/admin/shortcode.php' ); 
  133.  
  134. /**-----------------------------------------------------------------------------------*/ 
  135. /* Pages setting 
  136. /**-----------------------------------------------------------------------------------*/ 
  137.  
  138. require_once( G_LOCKER_PLUGIN_DIR . '/admin/pages.php' ); 
  139.  
  140. /** 
  141. * Add scripts for button 
  142. */ 
  143. function gl_admin_assets( $hook ) { 
  144.  
  145. global $wp_version; 
  146.  
  147. if ( version_compare( $wp_version, '3.9', '>=' ) ) { 
  148. if ( in_array( $hook, array('edit.php', 'post.php', 'post-new.php') ) ) { 
  149. ?> 
  150. <style> 
  151. i.g-locker-shortcode-icon { 
  152. background: url("<?php echo G_LOCKER_PLUGIN_URL ?>/assets/admin/img/g-locker-shortcode-icon.png"); 
  153. </style> 
  154. <?php 
  155.  
  156. add_action( 'admin_enqueue_scripts', 'gl_admin_assets' ); 
  157.  
  158. /** 
  159. * Add Social Button 
  160. */ 
  161. add_filter( 'mce_external_plugins', 'gl_add_plugin' ); 
  162. add_filter( 'mce_buttons', 'gl_register_button' ); 
  163.  
  164. function gl_register_button( $buttons ) { 
  165.  
  166. if ( !current_user_can( 'edit_posts' ) ) 
  167. return $buttons; 
  168. array_push( $buttons, "g_locker" ); 
  169. return $buttons; 
  170.  
  171. function gl_add_plugin( $plugin_array ) { 
  172.  
  173. if ( !current_user_can( 'edit_posts' ) ) 
  174. return $plugin_array; 
  175. global $wp_version; 
  176.  
  177. if ( version_compare( $wp_version, '3.9', '<' ) ) { 
  178. $plugin_array[ 'g_locker' ] = G_LOCKER_PLUGIN_URL . '/assets/admin/js/g_locker.tinymce3.js'; 
  179. } else { 
  180. $plugin_array[ 'g_locker' ] = G_LOCKER_PLUGIN_URL . '/assets/admin/js/g_locker.tinymce4.js'; 
  181.  
  182. return $plugin_array; 
  183. ?> 
.