| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( ! class_exists( 'MywpControllerAbstractModule' ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! class_exists( 'MywpControllerModuleMainGeneral' ) ) : |
| 12 |
|
| 13 |
final class MywpControllerModuleMainGeneral extends MywpControllerAbstractModule { |
| 14 |
|
| 15 |
static protected $id = 'main_general'; |
| 16 |
|
| 17 |
static protected $is_do_controller = true; |
| 18 |
|
| 19 |
protected static function after_init() { |
| 20 |
|
| 21 |
add_filter( 'mywp_controller_model_' . self::$id , array( __CLASS__ , 'mywp_controller_model' ) ); |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
public static function mywp_controller_model( $pre_model ) { |
| 26 |
|
| 27 |
$pre_model = true; |
| 28 |
|
| 29 |
return $pre_model; |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
public static function mywp_wp_loaded() { |
| 34 |
|
| 35 |
if( ! is_admin() ) { |
| 36 |
|
| 37 |
return false; |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
add_filter( 'plugin_row_meta' , array( __CLASS__ , 'plugin_row_meta' ) , 10 , 4 ); |
| 42 |
|
| 43 |
if( is_multisite() ) { |
| 44 |
|
| 45 |
add_filter( 'network_admin_plugin_action_links_' . MYWP_PLUGIN_BASENAME , array( __CLASS__ , 'plugin_action_links' ) , 10 , 4 ); |
| 46 |
|
| 47 |
} else { |
| 48 |
|
| 49 |
add_filter( 'plugin_action_links_' . MYWP_PLUGIN_BASENAME , array( __CLASS__ , 'plugin_action_links' ) , 10 , 4 ); |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
add_action( 'admin_body_class' , array( __CLASS__ , 'admin_body_class' ) ); |
| 54 |
|
| 55 |
add_action( 'all_admin_notices' , array( __CLASS__ , 'all_admin_notices' ) ); |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
private static function is_mywp_file( $plugin_file_name = false ) { |
| 60 |
|
| 61 |
if( empty( $plugin_file_name ) ) { |
| 62 |
|
| 63 |
return false; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
$plugin_file_name = strip_tags( $plugin_file_name ); |
| 68 |
|
| 69 |
if ( strpos( MYWP_PLUGIN_BASENAME , $plugin_file_name ) === false ) { |
| 70 |
|
| 71 |
return false; |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
return true; |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
public static function plugin_row_meta( $plugin_meta , $plugin_file , $plugin_data , $status ) { |
| 80 |
|
| 81 |
if ( ! self::is_mywp_file( $plugin_file ) ) { |
| 82 |
|
| 83 |
return $plugin_meta; |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
$plugin_info = MywpApi::plugin_info(); |
| 88 |
|
| 89 |
if( ! empty( $plugin_info['document_url'] ) ) { |
| 90 |
|
| 91 |
$plugin_meta[] = sprintf( '<a href="%1$s" target="_blank">%2$s</a>' , esc_url( $plugin_info['document_url'] ) , __( 'Documents' ) ); |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
if( ! empty( $plugin_info['forum_url'] ) ) { |
| 96 |
|
| 97 |
$plugin_meta[] = sprintf( '<a href="%1$s" target="_blank">%2$s</a>' , esc_url( $plugin_info['forum_url'] ) , __( 'Support Forums' ) ); |
| 98 |
|
| 99 |
} |
| 100 |
|
| 101 |
if( ! empty( $plugin_info['review_url'] ) ) { |
| 102 |
|
| 103 |
$plugin_meta[] = sprintf( '<a href="%1$s" target="_blank">%2$s</a>' , esc_url( $plugin_info['review_url'] ) , __( 'Review' , 'mywp' ) ); |
| 104 |
|
| 105 |
} |
| 106 |
|
| 107 |
$plugin_meta = apply_filters( 'mywp_plugin_row_meta' , $plugin_meta , $plugin_file , $plugin_data , $status ); |
| 108 |
|
| 109 |
return $plugin_meta; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
public static function plugin_action_links( $actions , $plugin_file , $plugin_data , $context ) { |
| 114 |
|
| 115 |
if ( ! self::is_mywp_file( $plugin_file ) ) { |
| 116 |
|
| 117 |
return $actions; |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
$plugin_info = MywpApi::plugin_info(); |
| 122 |
|
| 123 |
if( ! empty( $plugin_info['admin_url'] ) ) { |
| 124 |
|
| 125 |
$action_link = array( 'setting' => sprintf( '<a href="%1$s">%2$s</a>' , esc_url( $plugin_info['admin_url'] ) , __( 'Settings' ) ) ); |
| 126 |
|
| 127 |
$actions = wp_parse_args( $actions , $action_link ); |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
$actions = apply_filters( 'mywp_plugin_action_links' , $actions , $plugin_file , $plugin_data , $context ); |
| 132 |
|
| 133 |
return $actions; |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
public static function admin_body_class( $admin_body_class ) { |
| 138 |
|
| 139 |
$admin_body_class .= ' mywp '; |
| 140 |
|
| 141 |
if( MywpApi::is_manager() ) { |
| 142 |
|
| 143 |
$admin_body_class .= ' mywp-manager '; |
| 144 |
|
| 145 |
} |
| 146 |
|
| 147 |
return $admin_body_class; |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
public static function all_admin_notices() { |
| 152 |
|
| 153 |
$mywp_notice = new MywpNotice(); |
| 154 |
|
| 155 |
$notices = $mywp_notice->get_notices(); |
| 156 |
|
| 157 |
if( empty( $notices ) ) { |
| 158 |
|
| 159 |
return false; |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
if( ! empty( $notices['update'] ) ) { |
| 164 |
|
| 165 |
echo '<div class="updated mywp-notice">'; |
| 166 |
|
| 167 |
foreach( $notices['update'] as $message ) { |
| 168 |
|
| 169 |
printf( '<p class="update-notice">%s</p>' , $message ); |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
echo '</div>'; |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
if( ! empty( $notices['error'] ) ) { |
| 178 |
|
| 179 |
echo '<div class="error mywp-notice">'; |
| 180 |
|
| 181 |
foreach( $notices['error'] as $code => $message ) { |
| 182 |
|
| 183 |
printf( '<p class="error-notice error_%s">%s</p>' , $code , $message ); |
| 184 |
|
| 185 |
} |
| 186 |
|
| 187 |
echo '</div>'; |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
$mywp_notice->delete_notice(); |
| 192 |
|
| 193 |
} |
| 194 |
|
| 195 |
} |
| 196 |
|
| 197 |
MywpControllerModuleMainGeneral::init(); |
| 198 |
|
| 199 |
endif; |
| 200 |
|