PluginProbe
F4 Post Tree / trunk
F4 Post Tree vtrunk
trunk 1.0.2 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.18 1.1.19 1.1.2 1.1.20 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 All 29 releases
f4-tree / Core / Hooks.php

Hooks.php in F4 Post Tree trunk, at Core/Hooks.php

165 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace F4\TREE\Core;
4
5 /**
6 * Core Hooks
7 *
8 * All the WordPress hooks for the Core module
9 *
10 * @since 1.0.0
11 * @package F4\TREE\Core
12 */
13 class Hooks {
14 /**
15 * Initialize the hooks
16 *
17 * @since 1.0.0
18 * @access public
19 * @static
20 */
21 public static function init() {
22 add_action( 'init', __NAMESPACE__ . '\\Hooks::core_loaded' );
23 add_action( 'init', __NAMESPACE__ . '\\Hooks::load_textdomain' );
24 add_action( 'F4/TREE/Core/set_constants', __NAMESPACE__ . '\\Hooks::set_default_constants', 98 );
25 }
26
27 /**
28 * Fires once the core module is loaded
29 *
30 * @since 1.0.0
31 * @access public
32 * @static
33 */
34 public static function core_loaded() {
35 do_action( 'F4/TREE/Core/set_constants' );
36 do_action( 'F4/TREE/Core/loaded' );
37 add_action( 'admin_head', __NAMESPACE__ . '\\Hooks::add_admin_styles' );
38 add_action( 'admin_init', __NAMESPACE__ . '\\Hooks::register_settings' );
39 add_action( 'admin_menu', __NAMESPACE__ . '\\Hooks::register_options_page', 99 );
40 add_filter( 'plugin_action_links_' . F4_TREE_BASENAME, __NAMESPACE__ . '\\Hooks::add_settings_link_to_plugin_list' );
41 }
42
43 /**
44 * Sets the module default constants
45 *
46 * @since 1.0.0
47 * @access public
48 * @static
49 */
50 public static function set_default_constants() {
51 }
52
53 /**
54 * Load plugin textdomain
55 *
56 * @since 1.0.0
57 * @access public
58 * @static
59 */
60 public static function load_textdomain() {
61 load_plugin_textdomain( 'f4-tree', false, plugin_basename( F4_TREE_PATH . 'languages' ) . '/' );
62 }
63
64 /**
65 * Add admin styles
66 *
67 * @since 1.0.0
68 * @access public
69 * @static
70 */
71 public static function add_admin_styles() {
72 echo '<style>
73 .' . esc_html( F4_TREE_SLUG ) . '-submenu-item {
74 display: flex;
75 align-items: center;
76 white-space: nowrap;
77 }
78
79 .' . esc_html( F4_TREE_SLUG ) . '-submenu-item .f4-icon {
80 flex: 0 0 auto;
81 width: 1em;
82 height: 1em;
83 margin-right: 0.4em;
84 fill: currentColor;
85 }
86 </style>';
87 }
88
89 /**
90 * Register options page
91 *
92 * @since 1.0.0
93 * @access public
94 * @static
95 */
96 public static function register_options_page() {
97 $submenu_label = '
98 <span class="' . F4_TREE_SLUG . '-submenu-item">
99 <svg class="f4-icon" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"width="75px" height="100px" viewBox="0 0 75 100">
100 <path d="M74.295,21.04c0,1.38-1.122,2.504-2.502,2.504H54.259c-1.384,0-2.504-1.124-2.504-2.504V3.504
101 c0-1.379,1.12-2.504,2.504-2.504h17.534c1.38,0,2.502,1.125,2.502,2.504V21.04z"/>
102 <path d="M74.295,46.562c0,1.384-1.122,2.506-2.502,2.506H54.259c-1.384,0-2.504-1.122-2.504-2.506V29.029
103 c0-1.382,1.12-2.504,2.504-2.504h17.534c1.38,0,2.502,1.122,2.502,2.504V46.562z"/>
104 <path d="M74.295,72.086c0,1.384-1.122,2.506-2.502,2.506H54.259c-1.384,0-2.504-1.122-2.504-2.506V54.557
105 c0-1.387,1.12-2.506,2.504-2.506h17.534c1.38,0,2.502,1.119,2.502,2.506V72.086z"/>
106 <path d="M48.769,46.562c0,1.384-1.12,2.506-2.502,2.506H28.733c-1.384,0-2.504-1.122-2.504-2.506V29.029
107 c0-1.382,1.12-2.504,2.504-2.504h17.533c1.382,0,2.502,1.122,2.502,2.504V46.562z"/>
108 <path d="M48.769,72.086c0,1.384-1.12,2.506-2.502,2.506H28.733c-1.384,0-2.504-1.122-2.504-2.506V54.557
109 c0-1.387,1.12-2.506,2.504-2.506h17.533c1.382,0,2.502,1.119,2.502,2.506V72.086z"/>
110 <path d="M23.247,72.086c0,1.384-1.124,2.506-2.503,2.506H3.21c-1.384,0-2.505-1.122-2.505-2.506V54.557
111 c0-1.387,1.122-2.506,2.505-2.506h17.533c1.379,0,2.503,1.119,2.503,2.506V72.086z"/>
112 <path d="M53.833,98.412c-1.086,1.085-2.078,0.581-2.078-0.799V80.077c0-1.38,1.12-2.501,2.504-2.501h17.534
113 c1.38,0,1.768,1.106,0.798,2.075L53.833,98.412z"/>
114 <path d="M46.691,2.708c1.084-1.087,2.077-0.583,2.077,0.796v17.534c0,1.382-1.12,2.506-2.502,2.506H28.733
115 c-1.384,0-1.771-1.107-0.799-2.08L46.691,2.708z"/>
116 <path d="M21.167,28.229c1.086-1.085,2.08-0.582,2.08,0.8v17.532c0,1.384-1.124,2.506-2.503,2.506H3.21
117 c-1.384,0-1.773-1.107-0.801-2.078L21.167,28.229z"/>
118 </svg>
119
120 ' . __( 'Post Tree', 'f4-tree' ) . '
121 </span>
122 ';
123 add_options_page(
124 __( 'Post Tree Settings', 'f4-tree' ),
125 $submenu_label,
126 'manage_options',
127 'f4-tree-settings',
128 function () {
129 include F4_TREE_PATH . 'Core/views/admin-settings.php';
130 }
131 );
132 }
133
134 /**
135 * Register settings for options page
136 *
137 * @since 1.0.0
138 * @access public
139 * @static
140 */
141 public static function register_settings() {
142 register_setting( 'f4-tree-settings', 'f4-tree-settings', array(
143 'default' => array(
144 'post-types' => array(
145 'page' => '1',
146 'post' => '1',
147 ),
148 ),
149 ) );
150 }
151
152 /**
153 * Add settings link to plugin list
154 *
155 * @since 1.0.0
156 * @access public
157 * @static
158 */
159 public static function add_settings_link_to_plugin_list( $links ) {
160 array_push( $links, '<a href="' . admin_url( 'options-general.php?page=f4-tree-settings' ) . '">' . __( 'Settings' ) . '</a>' );
161 return $links;
162 }
163
164 }
165