PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/w3-total-cache/extensions/GenesisAdmin.php

https://gitlab.com/juanito.abelo/nlmobile
PHP | 317 lines | 269 code | 19 blank | 29 comment | 25 complexity | 1ffe71f0ac0b6f7fea409614bd273951 MD5 | raw file
  1. <?php
  2. /**
  3. * W3 GenesisExtension module
  4. */
  5. if (!defined('W3TC')) {
  6. die();
  7. }
  8. class W3_GenesisAdmin {
  9. function run() {
  10. add_action('admin_init', array($this, 'admin_init'));
  11. add_filter('w3tc_extensions', array($this, 'extension'), 10, 2);
  12. add_action('w3tc_extensions_page-genesis.theme', array($this, 'extension_header'));
  13. }
  14. /**
  15. * Display if caching or not.
  16. */
  17. function extension_header() {
  18. $config = w3_instance('W3_Config');
  19. $settings = w3tc_get_extension_config('genesis.theme');
  20. $caching = false;
  21. foreach($settings as $setting => $value) {
  22. if (strpos($setting, 'reject') === false && $value == '1') {
  23. $caching = true;
  24. break;
  25. }
  26. }
  27. echo '<p>';
  28. printf(__('The Genesis Framework extension is currently %s ', 'w3-total-cache'),
  29. ($caching ? '<span class="w3tc-enabled">' . __('enabled', 'w3-total-cache') . '</span>' :
  30. '<span class="w3tc-disabled">' . __('disabled', 'w3-total-cache') . '</span>'));
  31. if ($caching)
  32. printf(__('and caching via <strong>%s</strong>', 'w3-total-cahe'),$config->get_string('fragmentcache.engine'));
  33. echo '.</p>';
  34. }
  35. /**
  36. * Setups sections
  37. */
  38. function admin_init() {
  39. w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/extensions.php');
  40. // Register our settings field group
  41. w3tc_add_settings_section(
  42. 'header', // Unique identifier for the settings section
  43. 'Header', // Section title
  44. '__return_false', // Section callback (we don't want anything)
  45. 'genesis.theme' // extension id, used to uniquely identify the extension;
  46. );
  47. w3tc_add_settings_section(
  48. 'content',
  49. 'Content',
  50. '__return_false',
  51. 'genesis.theme'
  52. );
  53. w3tc_add_settings_section(
  54. 'sidebar',
  55. 'Sidebar',
  56. '__return_false',
  57. 'genesis.theme'
  58. );
  59. w3tc_add_settings_section(
  60. 'footer',
  61. 'Footer',
  62. '__return_false',
  63. 'genesis.theme'
  64. );
  65. w3tc_add_settings_section(
  66. 'exclusions',
  67. 'Disable fragment cache',
  68. '__return_false',
  69. 'genesis.theme'
  70. );
  71. $settings = $this->settings();
  72. foreach($settings as $setting => $meta) {
  73. /**
  74. * @var $label
  75. * @var $description
  76. * @var $section
  77. * @var $type
  78. */
  79. extract($meta);
  80. w3tc_add_settings_field($setting, $label,
  81. array($this, 'print_setting'), 'genesis.theme', $section,
  82. array('label_for'=>$setting, 'type'=>$type,
  83. 'description' => $description));
  84. }
  85. }
  86. /**
  87. *
  88. * @param $setting
  89. * @param $args
  90. */
  91. function print_setting($setting, $args) {
  92. w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/extensions.php');
  93. list($name, $id) = w3tc_get_name_and_id('genesis.theme', $setting);
  94. if ($args['type'] != 'custom')
  95. w3_ui_element($args['type'], $setting, $name, w3tc_get_extension_config('genesis.theme', $setting), w3_extension_is_sealed('genesis.theme'));
  96. else {
  97. if ($setting == 'reject_roles'):
  98. $saved_roles = w3tc_get_extension_config('genesis.theme', $setting);
  99. if (!is_array($saved_roles))
  100. $saved_roles = array();
  101. ?>
  102. <div id="<?php echo esc_attr($id)?>">
  103. <input type="hidden" name="<?php echo esc_attr($name)?>" value="" />
  104. <?php foreach( get_editable_roles() as $role_name => $role_data ) : ?>
  105. <input <?php disabled(w3_extension_is_sealed('genesis.theme')) ?> type="checkbox" name="<?php echo esc_attr($name)?>[]" value="<?php echo $role_name ?>" <?php checked( in_array( $role_name, $saved_roles ) ) ?> id="role_<?php echo $role_name ?>" />
  106. <label for="role_<?php echo $role_name ?>"><?php echo $role_data['name'] ?></label>
  107. <?php endforeach; ?>
  108. </div>
  109. <?php
  110. else:
  111. $saved_hooks = w3tc_get_extension_config('genesis.theme', $setting);
  112. if (!is_array($saved_hooks))
  113. $saved_hooks = array();
  114. $hooks = array('genesis_header' => 'Header', 'genesis_footer' => 'Footer', 'genesis_sidebar' => 'Sidebar', 'genesis_loop' =>'The Loop', 'wp_head' => 'wp_head', 'wp_footer' => 'wp_footer', 'genesis_comments' => 'Comments', 'genesis_pings' => 'Pings', 'genesis_do_nav'=>'Primary navigation', 'genesis_do_subnav' => 'Secondary navigation');?>
  115. <div id="<?php echo esc_attr($id)?>">
  116. <input <?php disabled(w3_extension_is_sealed('genesis.theme')) ?> type="hidden" name="<?php echo esc_attr($name)?>" value="" />
  117. <?php foreach( $hooks as $hook => $hook_label ) : ?>
  118. <input <?php disabled(w3_extension_is_sealed('genesis.theme')) ?> type="checkbox" name="<?php echo esc_attr($name)?>[]" value="<?php echo $hook ?>" <?php checked( in_array( $hook, $saved_hooks ) ) ?> id="role_<?php echo $hook ?>" />
  119. <label for="role_<?php echo $hook ?>"><?php echo $hook_label ?></label><br />
  120. <?php endforeach; ?>
  121. </div>
  122. <?php
  123. endif;
  124. }
  125. }
  126. /**
  127. * @param $extensions
  128. * @param W3_Config $config
  129. * @return mixed
  130. */
  131. function extension($extensions, $config) {
  132. $fc_enabled = ((w3_is_pro($config) || w3_is_enterprise($config)) &&
  133. $config->get_boolean('fragmentcache.enabled'));
  134. $activation_enabled = $fc_enabled && defined('PARENT_THEME_NAME') && PARENT_THEME_NAME == 'Genesis' &&
  135. defined('PARENT_THEME_VERSION') && version_compare(PARENT_THEME_VERSION, '1.9.0') >= 0;
  136. $message = array();
  137. if (is_network_admin()) {
  138. w3_require_once(W3TC_INC_FUNCTIONS_DIR . '/themes.php');
  139. $themes = w3tc_get_themes();
  140. $exists = false;
  141. foreach ($themes as $theme) {
  142. if (strtolower($theme->Template) == 'genesis')
  143. $exists = true;
  144. }
  145. if (!$exists)
  146. $message[] = 'Genesis Framework';
  147. } elseif (!(defined('PARENT_THEME_NAME') && PARENT_THEME_NAME == 'Genesis'))
  148. $message[] = 'Genesis Framework version >= 1.9.0';
  149. if (!$fc_enabled)
  150. $message[] = 'Fragment Cache (W3 Total Cache Pro)';
  151. $extensions['genesis.theme'] = array (
  152. 'name' => 'Genesis Framework',
  153. 'author' => 'W3 EDGE',
  154. 'description' => 'Provides 30-60% improvement in page generation time for the Genesis Framework by Copyblogger Media.',
  155. 'author uri' => 'http://www.w3-edge.com/',
  156. 'extension uri' => 'http://www.w3-edge.com/',
  157. 'extension id' => 'genesis.theme',
  158. 'version' => '0.1',
  159. 'enabled' => $activation_enabled,
  160. 'requirements' => implode(', ', $message),
  161. 'path' => 'w3-total-cache/extensions/Genesis.php'
  162. );
  163. return $extensions;
  164. }
  165. /**
  166. * @return array
  167. */
  168. function settings() {
  169. return
  170. array(
  171. 'wp_head' =>
  172. array(
  173. 'type' => 'checkbox',
  174. 'section' => 'header',
  175. 'label' => __('Cache wp_head loop:', 'w3-total-cache'),
  176. 'description' =>__('Cache wp_head. This includes the embedded CSS, JS etc.', 'w3-total-cache')
  177. ),
  178. 'genesis_header' =>
  179. array(
  180. 'type' => 'checkbox',
  181. 'section' => 'header',
  182. 'label' => __('Cache header:', 'w3-total-cache'),
  183. 'description' => __('Cache header loop. This is the area where the logo is located.', 'w3-total-cache')
  184. ),
  185. 'genesis_do_nav' =>
  186. array(
  187. 'type' => 'checkbox',
  188. 'section' => 'header',
  189. 'label' => __('Cache primary navigation:', 'w3-total-cache'),
  190. 'description' => __('Caches the navigation filter; per page.', 'w3-total-cache')
  191. ),
  192. 'genesis_do_subnav' =>
  193. array(
  194. 'type' => 'checkbox',
  195. 'section' => 'header',
  196. 'label' => __('Cache secondary navigation:', 'w3-total-cache'),
  197. 'description' => __('Caches secondary navigation filter; per page.', 'w3-total-cache'),
  198. ),
  199. 'loop_front_page' =>
  200. array(
  201. 'type' => 'checkbox',
  202. 'section' => 'content',
  203. 'label' => __('Cache front page post loop:', 'w3-total-cache'),
  204. 'description' => __('Caches the front page post loop, pagination is supported.', 'w3-total-cache')
  205. ),
  206. 'loop_terms' =>
  207. array(
  208. 'type' => 'checkbox',
  209. 'section' => 'content',
  210. 'label' => __('Cache author/tag/categories/term post loop:', 'w3-total-cache'),
  211. 'description' => __('Caches the posts listed on tag, categories, author and other term pages, pagination is supported.', 'w3-total-cache')
  212. ),
  213. 'flush_terms' =>
  214. array(
  215. 'type' => 'checkbox',
  216. 'section' => 'content',
  217. 'label' => __('Flush posts loop:', 'w3-total-cache'),
  218. 'description' => __('Flushes the posts loop cache on post updates. See setting above for affected loops.', 'w3-total-cache')
  219. ),
  220. 'loop_single' =>
  221. array(
  222. 'type' => 'checkbox',
  223. 'section' => 'content',
  224. 'label' => __('Cache single post / page:', 'w3-total-cache'),
  225. 'description' => __('Caches the single post / page loop, pagination is supported.', 'w3-total-cache')
  226. ),
  227. 'loop_single_excluded' =>
  228. array(
  229. 'type' => 'textarea',
  230. 'section' => 'content',
  231. 'label' => __('Excluded single pages / posts:', 'w3-total-cache'),
  232. 'description' => __('List of pages / posts that should not have the single post / post loop cached. Specify one page / post per line. This area supports regular expressions.', 'w3-total-cache')
  233. ),
  234. 'loop_single_genesis_comments' =>
  235. array(
  236. 'type' => 'checkbox',
  237. 'section' => 'content',
  238. 'label' => __('Cache comments:', 'w3-total-cache'),
  239. 'description' => __('Caches the comments loop, pagination is supported.', 'w3-total-cache')
  240. ),
  241. 'loop_single_genesis_pings' =>
  242. array(
  243. 'type' => 'checkbox',
  244. 'section' => 'content',
  245. 'label' => __('Cache pings:', 'w3-total-cache'),
  246. 'description' => __('Caches the ping loop, pagination is supported. One per line.', 'w3-total-cache')
  247. ),
  248. 'sidebar' =>
  249. array(
  250. 'type' => 'checkbox',
  251. 'section' => 'sidebar',
  252. 'label' => __('Cache sidebar:', 'w3-total-cache'),
  253. 'description' => __('Caches sidebar loop, the widget area.', 'w3-total-cache')
  254. ),
  255. 'sidebar_excluded' =>
  256. array(
  257. 'type' => 'textarea',
  258. 'section' => 'sidebar',
  259. 'label' => __('Exclude pages:', 'w3-total-cache'),
  260. 'description' => __('List of pages that should not have sidebar cached. Specify one page / post per line. This area supports regular expressions.', 'w3-total-cache')
  261. ),
  262. 'genesis_footer' =>
  263. array(
  264. 'type' => 'checkbox',
  265. 'section' => 'footer',
  266. 'label' => __('Cache footer:', 'w3-total-cache'),
  267. 'description' => __('Caches footer loop.', 'w3-total-cache')
  268. ),
  269. 'wp_footer' =>
  270. array(
  271. 'type' => 'checkbox',
  272. 'section' => 'footer',
  273. 'label' => __('Cache footer:', 'w3-total-cache'),
  274. 'description' => __('Caches wp_footer loop.', 'w3-total-cache')
  275. ),
  276. 'reject_logged_roles' =>
  277. array('type' => 'checkbox',
  278. 'section' => 'exclusions',
  279. 'label' => __('Disable fragment cache:', 'w3-total-cache'),
  280. 'description' => 'Don\'t use fragment cache with the following hooks and for the specified user roles.'
  281. ),
  282. 'reject_logged_roles_on_actions' =>
  283. array('type' => 'custom',
  284. 'section' => 'exclusions',
  285. 'label' => __('Select hooks:', 'w3-total-cache'),
  286. 'description' => __('Select hooks from the list that should not be cached if user belongs to any of the roles selected below.', 'w3-total-cache')
  287. ),
  288. 'reject_roles' =>
  289. array('type' => 'custom',
  290. 'section' => 'exclusions',
  291. 'label' => __('Select roles:', 'w3-total-cache'),
  292. 'description' => __('Select user roles that should not use the fragment cache.', 'w3-total-cache')
  293. )
  294. );
  295. }
  296. }
  297. $ext = new W3_GenesisAdmin();
  298. $ext->run();