PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.5
Pods – Custom Content Types and Fields v2.8.23.5
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / tribe-common / src / Tribe / Plugin_Meta_Links.php
pods / tribe-common / src / Tribe Last commit date
Admin 1 week ago Ajax 1 week ago Asset 1 week ago Context 1 week ago Customizer 1 week ago Debug_Bar 1 week ago Dialog 1 week ago Documentation 1 week ago Duplicate 1 week ago Editor 1 week ago Image 1 week ago JSON_LD 1 week ago Languages 1 week ago Log 1 week ago Meta 1 week ago Models 1 week ago PUE 1 week ago Process 1 week ago Promoter 1 week ago REST 1 week ago Repository 1 week ago Service_Providers 1 week ago Shortcode 1 week ago Support 1 week ago Tabbed_View 1 week ago Tooltip 1 week ago Traits 1 week ago Utils 1 week ago Validator 1 week ago Widget 1 week ago Abstract_Deactivation.php 1 week ago Abstract_Plugin_Register.php 1 week ago App_Shop.php 1 week ago Assets.php 1 week ago Assets_Pipeline.php 1 week ago Autoloader.php 1 week ago Cache.php 1 week ago Cache_Listener.php 1 week ago Changelog_Reader.php 1 week ago Container.php 1 week ago Context.php 1 week ago Cost_Utils.php 1 week ago Credits.php 1 week ago Customizer.php 1 week ago DB_Lock.php 1 week ago Data.php 1 week ago Date_Utils.php 1 week ago Db.php 1 week ago Debug.php 1 week ago Dependency.php 1 week ago Deprecation.php 1 week ago Editor.php 1 week ago Error.php 1 week ago Exception.php 1 week ago Extension.php 1 week ago Extension_Loader.php 1 week ago Feature_Detection.php 1 week ago Field.php 1 week ago Field_Conditional.php 1 week ago Freemius.php 1 week ago Log.php 1 week ago Main.php 1 week ago Notices.php 1 week ago Plugin_Meta_Links.php 1 week ago Plugins.php 1 week ago Plugins_API.php 1 week ago Post_History.php 1 week ago Post_Transient.php 1 week ago Promise.php 1 week ago Repository.php 1 week ago Rewrite.php 1 week ago Settings.php 1 week ago Settings_Manager.php 1 week ago Settings_Tab.php 1 week ago Simple_Table.php 1 week ago Support.php 1 week ago Tabbed_View.php 1 week ago Template.php 1 week ago Template_Factory.php 1 week ago Template_Part_Cache.php 1 week ago Templates.php 1 week ago Terms.php 1 week ago Timezones.php 1 week ago Tracker.php 1 week ago Updater.php 1 week ago Validate.php 1 week ago View_Helpers.php 1 week ago
Plugin_Meta_Links.php
148 lines
1 <?php
2 defined( 'WPINC' ) || die; // Do not load directly.
3
4 /**
5 * Filters meta links in the WP Admin > Plugins list
6 */
7 class Tribe__Plugin_Meta_Links {
8 /**
9 * Class instance
10 *
11 * @var Tribe__Plugin_Meta_Links The singleton instance.
12 */
13 private static $instance;
14
15 /**
16 * The various meta links that will be added
17 *
18 * @var array {
19 * Each plugin that will be filtered.
20 *
21 * @type array $plugin_basename {
22 * Meta links added to this plugin.
23 *
24 * @type array {
25 * Each individual link.
26 *
27 * @type string $html The full HTML for this link.
28 * @type bool $remove Whether we are adding or removing this link.
29 * }
30 * }
31 * }
32 */
33 private $meta_links = [];
34
35 /**
36 * Returns the singleton instance of this class.
37 *
38 * @return Tribe__Plugin_Meta_Links instance.
39 */
40 public static function instance() {
41 return null === self::$instance ? new self() : self::$instance;
42 }
43
44 private function __construct() {
45 add_action( 'plugin_row_meta', [ $this, 'filter_meta_links' ], 10, 2 );
46 }
47
48 /**
49 * Adds an <a> link to the meta list
50 *
51 * @param string $plugin Path to plugin file.
52 * @param string $text Inner text for HTML element.
53 * @param string $href URL for the link.
54 * @param array $attributes Key => value attributes for element.
55 */
56 public function add_link( $plugin, $title, $href, $attributes = [] ) {
57 $attributes['href'] = $href;
58
59 // Build the <a> element.
60 $html = '<a';
61
62 foreach ( $attributes as $att => $val ) {
63 $html .= ' ' . $att . '="' . esc_attr( $val ) . '"';
64 }
65
66 $html .= '>' . esc_html( $title ) . '</a>';
67
68 $this->set( $plugin, $html, false );
69 }
70
71 /**
72 * Adds or removes the specified HTML link
73 *
74 * @param string $plugin Path to plugin file.
75 * @param string $html Full HTML for this link.
76 * @param bool $remove Whether to add this HTML/link or match and remove it.
77 */
78 public function set( $plugin, $html, $remove = false ) {
79 $basename = plugin_basename( $plugin );
80
81 // Get any current links for this plugin.
82 $cur_links = Tribe__Utils__Array::get( $this->meta_links, $basename, [] );
83
84 $cur_links[] = [
85 'html' => $html,
86 'remove' => $remove,
87 ];
88
89 $this->meta_links = Tribe__Utils__Array::set( $this->meta_links, $basename, $cur_links );
90 }
91
92 /**
93 * Filters meta links on the plugins list page
94 *
95 * @param array $links The current plugin's links.
96 * @param string $basename The plugin currently being filtered.
97 *
98 * @return array Filtered action links array.
99 */
100 public function filter_meta_links( $links, $basename ) {
101 // Gets any links that are set for this plugin, defaults to an empty array.
102 $set_links = Tribe__Utils__Array::get( $this->meta_links, $basename, [] );
103
104 foreach ( $set_links as $link ) {
105
106 if ( true === $link['remove'] ) {
107 // Remove a link.
108 $pos = array_search( $link['html'], $links );
109
110 if ( false !== $pos ) {
111 unset( $links[ $pos ] );
112 }
113 } else {
114 // Add a link.
115 $links[] = $link['html'];
116 }
117 }
118
119 return $links;
120 }
121
122 /**
123 * Prevent cloning the singleton with 'clone' operator
124 *
125 * @return void
126 */
127 final private function __clone() {
128 _doing_it_wrong(
129 __FUNCTION__,
130 'Can not use this method on singletons.',
131 '4.3'
132 );
133 }
134
135 /**
136 * Prevent unserializing the singleton instance
137 *
138 * @return void
139 */
140 final private function __wakeup() {
141 _doing_it_wrong(
142 __FUNCTION__,
143 'Can not use this method on singletons.',
144 '4.3'
145 );
146 }
147 }
148