64 * @param bool $markup If the returned data should have HTML markup applied |
64 * @param bool $markup If the returned data should have HTML markup applied |
65 * @param bool $translate If the returned data should be translated |
65 * @param bool $translate If the returned data should be translated |
66 * @return array See above for description. |
66 * @return array See above for description. |
67 */ |
67 */ |
68 function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { |
68 function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { |
69 // We don't need to write to the file, so just open for reading. |
69 |
70 $fp = fopen($plugin_file, 'r'); |
70 $default_headers = array( |
71 |
71 'Name' => 'Plugin Name', |
72 // Pull only the first 8kiB of the file in. |
72 'PluginURI' => 'Plugin URI', |
73 $plugin_data = fread( $fp, 8192 ); |
73 'Version' => 'Version', |
74 |
74 'Description' => 'Description', |
75 // PHP will close file handle, but we are good citizens. |
75 'Author' => 'Author', |
76 fclose($fp); |
76 'AuthorURI' => 'Author URI', |
77 |
77 'TextDomain' => 'Text Domain', |
78 preg_match( '|Plugin Name:(.*)$|mi', $plugin_data, $name ); |
78 'DomainPath' => 'Domain Path' |
79 preg_match( '|Plugin URI:(.*)$|mi', $plugin_data, $uri ); |
79 ); |
80 preg_match( '|Version:(.*)|i', $plugin_data, $version ); |
80 |
81 preg_match( '|Description:(.*)$|mi', $plugin_data, $description ); |
81 $plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' ); |
82 preg_match( '|Author:(.*)$|mi', $plugin_data, $author_name ); |
82 |
83 preg_match( '|Author URI:(.*)$|mi', $plugin_data, $author_uri ); |
83 //For backward compatibility by default Title is the same as Name. |
84 preg_match( '|Text Domain:(.*)$|mi', $plugin_data, $text_domain ); |
84 $plugin_data['Title'] = $plugin_data['Name']; |
85 preg_match( '|Domain Path:(.*)$|mi', $plugin_data, $domain_path ); |
85 |
86 |
|
87 foreach ( array( 'name', 'uri', 'version', 'description', 'author_name', 'author_uri', 'text_domain', 'domain_path' ) as $field ) { |
|
88 if ( !empty( ${$field} ) ) |
|
89 ${$field} = _cleanup_header_comment(${$field}[1]); |
|
90 else |
|
91 ${$field} = ''; |
|
92 } |
|
93 |
|
94 $plugin_data = array( |
|
95 'Name' => $name, 'Title' => $name, 'PluginURI' => $uri, 'Description' => $description, |
|
96 'Author' => $author_name, 'AuthorURI' => $author_uri, 'Version' => $version, |
|
97 'TextDomain' => $text_domain, 'DomainPath' => $domain_path |
|
98 ); |
|
99 if ( $markup || $translate ) |
86 if ( $markup || $translate ) |
100 $plugin_data = _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup, $translate); |
87 $plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate ); |
101 |
88 |
102 return $plugin_data; |
89 return $plugin_data; |
103 } |
90 } |
104 |
91 |
105 function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) { |
92 function _get_plugin_data_markup_translate($plugin_file, $plugin_data, $markup = true, $translate = true) { |
106 |
93 |
107 //Translate fields |
94 //Translate fields |
108 if( $translate && ! empty($plugin_data['TextDomain']) ) { |
95 if( $translate && ! empty($plugin_data['TextDomain']) ) { |
109 if( ! empty( $plugin_data['DomainPath'] ) ) |
96 if( ! empty( $plugin_data['DomainPath'] ) ) |
110 load_plugin_textdomain($plugin_data['TextDomain'], dirname($plugin_file). $plugin_data['DomainPath']); |
97 load_plugin_textdomain($plugin_data['TextDomain'], false, dirname($plugin_file). $plugin_data['DomainPath']); |
111 else |
98 else |
112 load_plugin_textdomain($plugin_data['TextDomain'], dirname($plugin_file)); |
99 load_plugin_textdomain($plugin_data['TextDomain'], false, dirname($plugin_file)); |
113 |
100 |
114 foreach ( array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field ) |
101 foreach ( array('Name', 'PluginURI', 'Description', 'Author', 'AuthorURI', 'Version') as $field ) |
115 $plugin_data[ $field ] = translate($plugin_data[ $field ], $plugin_data['TextDomain']); |
102 $plugin_data[ $field ] = translate($plugin_data[ $field ], $plugin_data['TextDomain']); |
116 } |
103 } |
117 |
104 |
341 |
330 |
342 foreach ( $plugins as $plugin ) { |
331 foreach ( $plugins as $plugin ) { |
343 $plugin = plugin_basename($plugin); |
332 $plugin = plugin_basename($plugin); |
344 if( ! is_plugin_active($plugin) ) |
333 if( ! is_plugin_active($plugin) ) |
345 continue; |
334 continue; |
346 array_splice($current, array_search( $plugin, $current), 1 ); // Fixed Array-fu! |
335 if ( ! $silent ) |
347 if ( ! $silent ) //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output. |
336 do_action( 'deactivate_plugin', trim( $plugin ) ); |
348 do_action('deactivate_' . trim( $plugin )); |
337 |
|
338 $key = array_search( $plugin, (array) $current ); |
|
339 |
|
340 if ( false !== $key ) |
|
341 array_splice( $current, $key, 1 ); |
|
342 |
|
343 //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output. |
|
344 if ( ! $silent ) { |
|
345 do_action( 'deactivate_' . trim( $plugin ) ); |
|
346 do_action( 'deactivated_plugin', trim( $plugin ) ); |
|
347 } |
349 } |
348 } |
350 |
349 |
351 update_option('active_plugins', $current); |
350 update_option('active_plugins', $current); |
352 } |
351 } |
353 |
352 |
582 |
581 |
583 // |
582 // |
584 // Menu |
583 // Menu |
585 // |
584 // |
586 |
585 |
587 function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '' ) { |
586 function add_menu_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '', $position = NULL ) { |
588 global $menu, $admin_page_hooks, $_registered_pages; |
587 global $menu, $admin_page_hooks, $_registered_pages; |
589 |
588 |
590 $file = plugin_basename( $file ); |
589 $file = plugin_basename( $file ); |
591 |
590 |
592 $admin_page_hooks[$file] = sanitize_title( $menu_title ); |
591 $admin_page_hooks[$file] = sanitize_title( $menu_title ); |
593 |
592 |
594 $hookname = get_plugin_page_hookname( $file, '' ); |
593 $hookname = get_plugin_page_hookname( $file, '' ); |
595 if (!empty ( $function ) && !empty ( $hookname )) |
594 if (!empty ( $function ) && !empty ( $hookname )) |
596 add_action( $hookname, $function ); |
595 add_action( $hookname, $function ); |
597 |
596 |
598 if ( empty($icon_url) ) |
597 if ( empty($icon_url) ) { |
599 $icon_url = 'images/generic.png'; |
598 $icon_url = 'images/generic.png'; |
600 elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) |
599 } elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) { |
601 $icon_url = 'https://' . substr($icon_url, 7); |
600 $icon_url = 'https://' . substr($icon_url, 7); |
602 |
601 } |
603 $menu[] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); |
602 |
|
603 $new_menu = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); |
|
604 |
|
605 if ( NULL === $position ) { |
|
606 $menu[] = $new_menu; |
|
607 } else { |
|
608 $menu[$position] = $new_menu; |
|
609 } |
604 |
610 |
605 $_registered_pages[$hookname] = true; |
611 $_registered_pages[$hookname] = true; |
606 |
612 |
607 return $hookname; |
613 return $hookname; |
608 } |
614 } |
609 |
615 |
610 function add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') { |
616 function add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') { |
611 global $menu, $admin_page_hooks, $_wp_last_object_menu, $_registered_pages; |
617 global $_wp_last_object_menu; |
612 |
|
613 $file = plugin_basename( $file ); |
|
614 |
|
615 $admin_page_hooks[$file] = sanitize_title( $menu_title ); |
|
616 |
|
617 $hookname = get_plugin_page_hookname( $file, '' ); |
|
618 if (!empty ( $function ) && !empty ( $hookname )) |
|
619 add_action( $hookname, $function ); |
|
620 |
|
621 if ( empty($icon_url) ) |
|
622 $icon_url = 'images/generic.png'; |
|
623 |
618 |
624 $_wp_last_object_menu++; |
619 $_wp_last_object_menu++; |
625 |
620 |
626 $menu[$_wp_last_object_menu] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); |
621 return add_menu_page($page_title, $menu_title, $access_level, $file, $function, $icon_url, $_wp_last_object_menu); |
627 |
|
628 $_registered_pages[$hookname] = true; |
|
629 |
|
630 return $hookname; |
|
631 } |
622 } |
632 |
623 |
633 function add_utility_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') { |
624 function add_utility_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '') { |
634 global $menu, $admin_page_hooks, $_wp_last_utility_menu, $_registered_pages; |
625 global $_wp_last_utility_menu; |
635 |
|
636 $file = plugin_basename( $file ); |
|
637 |
|
638 $admin_page_hooks[$file] = sanitize_title( $menu_title ); |
|
639 |
|
640 $hookname = get_plugin_page_hookname( $file, '' ); |
|
641 if (!empty ( $function ) && !empty ( $hookname )) |
|
642 add_action( $hookname, $function ); |
|
643 |
|
644 if ( empty($icon_url) ) |
|
645 $icon_url = 'images/generic.png'; |
|
646 elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) |
|
647 $icon_url = 'https://' . substr($icon_url, 7); |
|
648 |
626 |
649 $_wp_last_utility_menu++; |
627 $_wp_last_utility_menu++; |
650 |
628 |
651 $menu[$_wp_last_utility_menu] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); |
629 return add_menu_page($page_title, $menu_title, $access_level, $file, $function, $icon_url, $_wp_last_utility_menu); |
652 |
|
653 $_registered_pages[$hookname] = true; |
|
654 |
|
655 return $hookname; |
|
656 } |
630 } |
657 |
631 |
658 function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) { |
632 function add_submenu_page( $parent, $page_title, $menu_title, $access_level, $file, $function = '' ) { |
659 global $submenu; |
633 global $submenu; |
660 global $menu; |
634 global $menu; |