public function __construct() { $self = new \ReflectionClass($this); $public_methods = $self->getMethods(\ReflectionMethod::IS_PUBLIC); if (empty($public_methods)) { return; } foreach ($public_methods as $method) { if ($method->name != '__construct') { // Parse string $signature = new GString($method->name); // Convert CamelCase to forward slash syntax and double underscore to a dash in // for bbPress. Also support and accomodate incompatible action names i.e. load-index.php // post-new.php in CPT, ACF, etc. $signature = $signature->replaceAll('([A-Z])', '/$0')->replace('__', '-')->replace('load_index_php', 'load-index.php')->replace('_php', '.php'); // Optimized for speed, handle acf only if present if (strpos($method->name, 'acf_') !== false) { $signature = $signature->replace('acf_helpers_', 'acf/helpers/')->replace('acf_location_rule_types', 'acf/location/rule_types')->replace('acf_location_rule_values_', 'acf/location/rule_values/')->replace('acf_options_page_', 'acf/options_page/')->replace('acf_input_', 'acf/input/')->replace('acf_', 'acf/'); } $name = (string) $signature->toLowerCase(); $params = $method->getNumberOfParameters(); // Check for activation, deactivation, uninstall hooks if ($name == 'activation') { register_activation_hook(__FILE__, array($this, $method->name)); } elseif ($name == 'deactivation') { register_deactivation_hook(__FILE__, array($this, $method->name)); } elseif ($name == 'uninstall') { register_uninstall_hook(__FILE__, array($this, $method->name)); // Look for shortcode definition } elseif ($signature->getLeftMost('_')->equals('shortcode')) { $signature = new GString($name); add_shortcode((string) $signature->delLeftMost('_'), array($this, $method->name)); // Assume for action/filter hook definition } else { // Check for priority option $priority = (string) $signature->getRightMost('_'); if (is_numeric($priority)) { $priority = (int) $priority; $signature = new GString($name); $name = (string) $signature->delRightMost('_'); } else { $priority = 10; } add_filter($name, array($this, $method->name), $priority, $params); } } } }
/** * Provide persistent menu icon and set default screen layout. */ function admin_head_1() { global $wp_post_types; $css = ''; foreach ($wp_post_types as $post_type => $args) { if (strpos($args->menu_icon_font, '\\e') !== false) { $menu = new GString($args->menu_icon_font); $font = (string) $menu->getLeftMost(' '); $char = (string) $menu->delLeftMost(' '); $css .= "a.menu-icon-" . $post_type; $css .= " div.wp-menu-image:before { font: 400 20px/1 " . $font; $css .= " !important; content: '" . $char . "'; }\n"; } // Set the default screen layout (1 or 2 columns) for the current user. if (get_user_meta(get_current_user_id(), 'screen_layout_' . $post_type, true) === '') { update_user_meta(get_current_user_id(), 'screen_layout_' . $post_type, $args->default_screen_layout); } } if ($css !== '') { echo "<style type=\"text/css\">\n" . $css . "</style>\n"; } }