(一)中讲到了wordpress是如何读取系统中所有插件的。
现在我们来看看她是如何激活及停用插件的。
激活及停用插件
wordpress的当前使用的插件列表存放在数据库中,wp_options表,字段option_name值为active_plugins的列存放的就是当前系统中使用的插件。
a:2:{i:0;s:9:"hello.php";i:1;s:16:"wp-db-backup.php";}
就是当前系统中使用的两个插件Hello Dolly、WordPress Database Backup。
这个字段原有类型是array,经过serialize后存放在数据库中,读出时unserialize。
取得当前系统中使用的插件 functions.php | 273行 | function get_settings($setting) {}
-    
-        
-     $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1");    
-         
-        
-    
-     if( is_object( $row) ) {    
-         $value = $row->option_value;    
-            
-         wp_cache_set($setting, $value, 'options');    
-     }    
-         
-        
-     return apply_filters( 'option_' . $setting, maybe_unserialize($value) );    
-         
-        
-        
-    
-        
-       
-   
-   
-   
-   
-   
-   
 
激活插件
通过链接plugins.php?action=activate&plugin=hello.php
wp-admin/plugins.php | 5行左右 | 
-    
- $current = get_settings('active_plugins');    
-    
- if (!in_array($_GET['plugin'], $current)) {    
-        
-     $current[] = trim( $_GET['plugin'] );    
-     sort($current);    
-        
-        
-     update_option('active_plugins', $current);    
-         
-        
- }  
 
停用插件
通过链接plugins.php?action=deactivate&plugin=hello.php
wp-admin/plugins.php | 16行左右 | 
-    
- $current = get_settings('active_plugins');    
-    
- array_splice($current, array_search( $_GET['plugin'], $current), 1 );    
-    
-    
- update_option('active_plugins', $current);    
-    
-   
 
                     
                                        
目前没有留言,等您坐沙发呢!