PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.3.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.3.1
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
insert-php / libs / factory / pages / pages.php

pages.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.3.1, at libs/factory/pages/pages.php

108 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * A group of classes and methods to create and manage pages.
4 *
5 * @author Alex Kovalev <alex.kovalevv@gmail.com>
6 * @copyright (c) 2018, Webcraftic Ltd
7 *
8 * @package core
9 * @since 1.0.0
10 */
11
12 // Exit if accessed directly
13 if( !defined('ABSPATH') ) {
14 exit;
15 }
16
17 add_action('admin_menu', 'Wbcr_FactoryPages422::actionAdminMenu');
18 add_action('network_admin_menu', 'Wbcr_FactoryPages422::actionAdminMenu');
19
20 if( !class_exists('Wbcr_FactoryPages422') ) {
21 /**
22 * A base class to manage pages.
23 *
24 * @since 1.0.0
25 */
26 class Wbcr_FactoryPages422 {
27
28 /**
29 * @var Wbcr_FactoryPages422_Page[]
30 */
31 private static $pages = array();
32
33 /**
34 * @param Wbcr_Factory422_Plugin $plugin
35 * @param $class_name
36 */
37 public static function register($plugin, $class_name)
38 {
39 if( !isset(self::$pages[$plugin->getPluginName()]) ) {
40 self::$pages[$plugin->getPluginName()] = array();
41 }
42 $page = new $class_name($plugin);
43 if( is_multisite() && is_network_admin() && !$page->available_for_multisite ) {
44 return;
45 }
46 self::$pages[$plugin->getPluginName()][] = $page;
47 }
48
49 public static function actionAdminMenu()
50 {
51 if( empty(self::$pages) ) {
52 return;
53 }
54
55 foreach(self::$pages as $plugin_pages) {
56 foreach($plugin_pages as $page) {
57 $page->connect();
58 }
59 }
60 }
61
62 public static function getPageUrl(Wbcr_Factory422_Plugin $plugin, $page_id, $args = array())
63 {
64 if( isset(self::$pages[$plugin->getPluginName()]) ) {
65 $pages = self::$pages[$plugin->getPluginName()];
66
67 foreach($pages as $page) {
68 if( $page->id == $page_id ) {
69 return $page->getBaseUrl($page_id, $args);
70 }
71 }
72 } else {
73 _doing_it_wrong(__METHOD__, __('You are trying to call this earlier than the plugin menu will be registered.'), '4.0.8');
74 }
75 }
76
77 /**
78 * @param Wbcr_Factory422_Plugin $plugin
79 * @return array
80 */
81 public static function getIds($plugin)
82 {
83 if( !isset(self::$pages[$plugin->getPluginName()]) ) {
84 return array();
85 }
86
87 $result = array();
88 foreach(self::$pages[$plugin->getPluginName()] as $page)
89 $result[] = $page->getResultId();
90
91 return $result;
92 }
93 }
94 }
95
96 if( !function_exists('wbcr_factory_pages_422_get_page_id') ) {
97 /**
98 *
99 * @param Wbcr_Factory422_Plugin $plugin
100 * @param string $page_id
101 * @return string
102 */
103 function wbcr_factory_pages_422_get_page_id($plugin, $page_id)
104 {
105 return $page_id . '-' . $plugin->getPluginName();
106 }
107 }
108