| 1 |
<?php |
| 2 |
|
| 3 |
namespace LIBRARY; |
| 4 |
|
| 5 |
|
| 6 |
class Helpers { |
| 7 |
|
| 8 |
public static $demo_import_start_time = ''; |
| 9 |
|
| 10 |
public static function validate_import_file_info( $import_files ) { |
| 11 |
$filtered_import_file_info = array(); |
| 12 |
|
| 13 |
foreach ( $import_files as $import_file ) { |
| 14 |
if ( self::is_import_file_info_format_correct( $import_file ) ) { |
| 15 |
$filtered_import_file_info[] = $import_file; |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
return $filtered_import_file_info; |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
private static function is_import_file_info_format_correct( $import_file_info ) { |
| 24 |
if ( empty( $import_file_info['import_file_name'] ) ) { |
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
return true; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
public static function download_import_files( $import_file_info ) { |
| 33 |
$downloaded_files = array( |
| 34 |
'content' => '', |
| 35 |
'widgets' => '', |
| 36 |
'customizer' => '', |
| 37 |
'redux' => '', |
| 38 |
); |
| 39 |
$downloader = new Downloader(); |
| 40 |
|
| 41 |
$import_file_info = self::apply_filters('library/pre_download_import_files', $import_file_info); |
| 42 |
|
| 43 |
if ( empty( $import_file_info['import_file_url'] ) ) { |
| 44 |
if ( file_exists( $import_file_info['local_import_file'] ) ) { |
| 45 |
$downloaded_files['content'] = $import_file_info['local_import_file']; |
| 46 |
} |
| 47 |
} |
| 48 |
else { |
| 49 |
$content_filename = self::apply_filters( 'library/downloaded_content_file_prefix', 'demo-content-import-file_' ) . self::$demo_import_start_time . self::apply_filters( 'library/downloaded_content_file_suffix_and_file_extension', '.xml' ); |
| 50 |
|
| 51 |
$downloaded_files['content'] = $downloader->download_file( $import_file_info['import_file_url'], $content_filename ); |
| 52 |
|
| 53 |
if ( is_wp_error( $downloaded_files['content'] ) ) { |
| 54 |
return $downloaded_files['content']; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
if ( ! empty( $import_file_info['import_widget_file_url'] ) ) { |
| 59 |
$widget_filename = self::apply_filters( 'library/downloaded_widgets_file_prefix', 'demo-widgets-import-file_' ) . self::$demo_import_start_time . self::apply_filters( 'library/downloaded_widgets_file_suffix_and_file_extension', '.json' ); |
| 60 |
|
| 61 |
$downloaded_files['widgets'] = $downloader->download_file( $import_file_info['import_widget_file_url'], $widget_filename ); |
| 62 |
|
| 63 |
if ( is_wp_error( $downloaded_files['widgets'] ) ) { |
| 64 |
return $downloaded_files['widgets']; |
| 65 |
} |
| 66 |
} |
| 67 |
else if ( ! empty( $import_file_info['local_import_widget_file'] ) ) { |
| 68 |
if ( file_exists( $import_file_info['local_import_widget_file'] ) ) { |
| 69 |
$downloaded_files['widgets'] = $import_file_info['local_import_widget_file']; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
if ( ! empty( $import_file_info['import_customizer_file_url'] ) ) { |
| 74 |
$customizer_filename = self::apply_filters( 'library/downloaded_customizer_file_prefix', 'demo-customizer-import-file_' ) . self::$demo_import_start_time . self::apply_filters( 'library/downloaded_customizer_file_suffix_and_file_extension', '.dat' ); |
| 75 |
|
| 76 |
$downloaded_files['customizer'] = $downloader->download_file( $import_file_info['import_customizer_file_url'], $customizer_filename ); |
| 77 |
|
| 78 |
if ( is_wp_error( $downloaded_files['customizer'] ) ) { |
| 79 |
return $downloaded_files['customizer']; |
| 80 |
} |
| 81 |
} |
| 82 |
else if ( ! empty( $import_file_info['local_import_customizer_file'] ) ) { |
| 83 |
if ( file_exists( $import_file_info['local_import_customizer_file'] ) ) { |
| 84 |
$downloaded_files['customizer'] = $import_file_info['local_import_customizer_file']; |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
if ( ! empty( $import_file_info['import_redux'] ) && is_array( $import_file_info['import_redux'] ) ) { |
| 89 |
$redux_items = array(); |
| 90 |
|
| 91 |
foreach ( $import_file_info['import_redux'] as $index => $redux_item ) { |
| 92 |
$redux_filename = self::apply_filters( 'library/downloaded_redux_file_prefix', 'demo-redux-import-file_' ) . $index . '-' . self::$demo_import_start_time . self::apply_filters( 'library/downloaded_redux_file_suffix_and_file_extension', '.json' ); |
| 93 |
|
| 94 |
$file_path = $downloader->download_file( $redux_item['file_url'], $redux_filename ); |
| 95 |
|
| 96 |
if ( is_wp_error( $file_path ) ) { |
| 97 |
return $file_path; |
| 98 |
} |
| 99 |
|
| 100 |
$redux_items[] = array( |
| 101 |
'option_name' => $redux_item['option_name'], |
| 102 |
'file_path' => $file_path, |
| 103 |
); |
| 104 |
} |
| 105 |
|
| 106 |
$downloaded_files['redux'] = $redux_items; |
| 107 |
} |
| 108 |
else if ( ! empty( $import_file_info['local_import_redux'] ) ) { |
| 109 |
|
| 110 |
$redux_items = array(); |
| 111 |
|
| 112 |
foreach ( $import_file_info['local_import_redux'] as $redux_item ) { |
| 113 |
if ( file_exists( $redux_item['file_path'] ) ) { |
| 114 |
$redux_items[] = $redux_item; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
$downloaded_files['redux'] = $redux_items; |
| 119 |
} |
| 120 |
|
| 121 |
return $downloaded_files; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
public static function write_to_file( $content, $file_path ) { |
| 126 |
$verified_credentials = self::check_wp_filesystem_credentials(); |
| 127 |
|
| 128 |
if ( is_wp_error( $verified_credentials ) ) { |
| 129 |
return $verified_credentials; |
| 130 |
} |
| 131 |
|
| 132 |
global $wp_filesystem; |
| 133 |
|
| 134 |
if ( ! $wp_filesystem->put_contents( $file_path, $content ) ) { |
| 135 |
return new \WP_Error( |
| 136 |
'failed_writing_file_to_server', |
| 137 |
sprintf( |
| 138 |
__( 'An error occurred while writing file to your server! Tried to write a file to: %1$s%2$s.', 'borderless' ), |
| 139 |
'<br>', |
| 140 |
$file_path |
| 141 |
) |
| 142 |
); |
| 143 |
} |
| 144 |
|
| 145 |
return $file_path; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
public static function append_to_file( $content, $file_path, $separator_text = '' ) { |
| 150 |
$verified_credentials = self::check_wp_filesystem_credentials(); |
| 151 |
|
| 152 |
if ( is_wp_error( $verified_credentials ) ) { |
| 153 |
return $verified_credentials; |
| 154 |
} |
| 155 |
|
| 156 |
global $wp_filesystem; |
| 157 |
|
| 158 |
$existing_data = ''; |
| 159 |
if ( file_exists( $file_path ) ) { |
| 160 |
$existing_data = $wp_filesystem->get_contents( $file_path ); |
| 161 |
} |
| 162 |
|
| 163 |
$separator = PHP_EOL . '---' . $separator_text . '---' . PHP_EOL; |
| 164 |
|
| 165 |
if ( ! $wp_filesystem->put_contents( $file_path, $existing_data . $separator . $content . PHP_EOL ) ) { |
| 166 |
return new \WP_Error( |
| 167 |
'failed_writing_file_to_server', |
| 168 |
sprintf( |
| 169 |
__( 'An error occurred while writing file to your server! Tried to write a file to: %1$s%2$s.', 'borderless' ), |
| 170 |
'<br>', |
| 171 |
$file_path |
| 172 |
) |
| 173 |
); |
| 174 |
} |
| 175 |
|
| 176 |
return true; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
public static function data_from_file( $file_path ) { |
| 181 |
$verified_credentials = self::check_wp_filesystem_credentials(); |
| 182 |
|
| 183 |
if ( is_wp_error( $verified_credentials ) ) { |
| 184 |
return $verified_credentials; |
| 185 |
} |
| 186 |
|
| 187 |
global $wp_filesystem; |
| 188 |
|
| 189 |
$data = $wp_filesystem->get_contents( $file_path ); |
| 190 |
|
| 191 |
if ( ! $data ) { |
| 192 |
return new \WP_Error( |
| 193 |
'failed_reading_file_from_server', |
| 194 |
sprintf( |
| 195 |
__( 'An error occurred while reading a file from your server! Tried reading file from path: %1$s%2$s.', 'borderless' ), |
| 196 |
'<br>', |
| 197 |
$file_path |
| 198 |
) |
| 199 |
); |
| 200 |
} |
| 201 |
|
| 202 |
return $data; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
private static function check_wp_filesystem_credentials() { |
| 207 |
if ( ! ( 'direct' === get_filesystem_method() ) ) { |
| 208 |
return new \WP_Error( |
| 209 |
'no_direct_file_access', |
| 210 |
sprintf( |
| 211 |
__( 'This WordPress page does not have %1$sdirect%2$s write file access. This plugin needs it in order to save the demo import xml file to the upload directory of your site. You can change this setting with these instructions: %3$s.', 'borderless' ), |
| 212 |
'<strong>', |
| 213 |
'</strong>', |
| 214 |
'<a href="http://gregorcapuder.com/wordpress-how-to-set-direct-filesystem-method/" target="_blank">How to set <strong>direct</strong> filesystem method</a>' |
| 215 |
) |
| 216 |
); |
| 217 |
} |
| 218 |
|
| 219 |
$plugin_page_setup = self::get_plugin_page_setup_data(); |
| 220 |
$demo_import_page_url = wp_nonce_url( $plugin_page_setup['parent_slug'] . '?page=' . $plugin_page_setup['menu_slug'], $plugin_page_setup['menu_slug'] ); |
| 221 |
|
| 222 |
if ( false === ( $creds = request_filesystem_credentials( $demo_import_page_url, '', false, false, null ) ) ) { |
| 223 |
return new \WP_error( |
| 224 |
'filesystem_credentials_could_not_be_retrieved', |
| 225 |
__( 'An error occurred while retrieving reading/writing permissions to your server (could not retrieve WP filesystem credentials)!', 'borderless' ) |
| 226 |
); |
| 227 |
} |
| 228 |
|
| 229 |
if ( ! WP_Filesystem( $creds ) ) { |
| 230 |
return new \WP_Error( |
| 231 |
'wrong_login_credentials', |
| 232 |
__( 'Your WordPress login credentials don\'t allow to use WP_Filesystem!', 'borderless' ) |
| 233 |
); |
| 234 |
} |
| 235 |
|
| 236 |
return true; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
public static function get_log_path() { |
| 241 |
$upload_dir = wp_upload_dir(); |
| 242 |
$upload_path = self::apply_filters( 'library/upload_file_path', trailingslashit( $upload_dir['path'] ) ); |
| 243 |
|
| 244 |
$log_path = $upload_path . self::apply_filters( 'library/log_file_prefix', 'log_file_' ) . self::$demo_import_start_time . self::apply_filters( 'library/log_file_suffix_and_file_extension', '.txt' ); |
| 245 |
|
| 246 |
self::register_file_as_media_attachment( $log_path ); |
| 247 |
|
| 248 |
return $log_path; |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
public static function register_file_as_media_attachment( $log_path ) { |
| 253 |
$log_mimes = array( 'txt' => 'text/plain' ); |
| 254 |
$filetype = wp_check_filetype( basename( $log_path ), self::apply_filters( 'library/file_mimes', $log_mimes ) ); |
| 255 |
|
| 256 |
$attachment = array( |
| 257 |
'guid' => self::get_log_url( $log_path ), |
| 258 |
'post_mime_type' => $filetype['type'], |
| 259 |
'post_title' => self::apply_filters( 'library/attachment_prefix', esc_html__( 'One Click Demo Import - ', 'borderless' ) ) . preg_replace( '/\.[^.]+$/', '', basename( $log_path ) ), |
| 260 |
'post_content' => '', |
| 261 |
'post_status' => 'inherit', |
| 262 |
); |
| 263 |
|
| 264 |
$attach_id = wp_insert_attachment( $attachment, $log_path ); |
| 265 |
} |
| 266 |
|
| 267 |
|
| 268 |
public static function get_log_url( $log_path ) { |
| 269 |
$upload_dir = wp_upload_dir(); |
| 270 |
$upload_url = self::apply_filters( 'library/upload_file_url', trailingslashit( $upload_dir['url'] ) ); |
| 271 |
|
| 272 |
return $upload_url . basename( $log_path ); |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
public static function verify_ajax_call() { |
| 277 |
check_ajax_referer( 'library-ajax-verification', 'security' ); |
| 278 |
|
| 279 |
if ( ! current_user_can( 'import' ) ) { |
| 280 |
wp_die( |
| 281 |
sprintf( |
| 282 |
__( '%1$sYour user role isn\'t high enough. You don\'t have permission to import demo data.%2$s', 'borderless' ), |
| 283 |
'<div class="notice notice-error"><p>', |
| 284 |
'</p></div>' |
| 285 |
) |
| 286 |
); |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
public static function process_uploaded_files( $uploaded_files, $log_file_path ) { |
| 292 |
$selected_import_files = array( |
| 293 |
'content' => '', |
| 294 |
'widgets' => '', |
| 295 |
'customizer' => '', |
| 296 |
'redux' => '', |
| 297 |
); |
| 298 |
|
| 299 |
$upload_overrides = array( |
| 300 |
'test_form' => false, |
| 301 |
); |
| 302 |
|
| 303 |
add_filter( 'upload_mimes', function ( $defaults ) { |
| 304 |
$custom = [ |
| 305 |
'xml' => 'text/xml', |
| 306 |
'json' => 'application/json', |
| 307 |
'wie' => 'application/json', |
| 308 |
'dat' => 'text/plain', |
| 309 |
]; |
| 310 |
|
| 311 |
return array_merge( $custom, $defaults ); |
| 312 |
} ); |
| 313 |
|
| 314 |
$file_not_provided_error = array( |
| 315 |
'error' => esc_html__( 'No file provided.', 'borderless' ) |
| 316 |
); |
| 317 |
|
| 318 |
$content_file_info = isset( $_FILES['content_file'] ) ? |
| 319 |
wp_handle_upload( $_FILES['content_file'], $upload_overrides ) : |
| 320 |
$file_not_provided_error; |
| 321 |
|
| 322 |
$widget_file_info = isset( $_FILES['widget_file'] ) ? |
| 323 |
wp_handle_upload( $_FILES['widget_file'], $upload_overrides ) : |
| 324 |
$file_not_provided_error; |
| 325 |
|
| 326 |
$customizer_file_info = isset( $_FILES['customizer_file'] ) ? |
| 327 |
wp_handle_upload( $_FILES['customizer_file'], $upload_overrides ) : |
| 328 |
$file_not_provided_error; |
| 329 |
|
| 330 |
$redux_file_info = isset( $_FILES['redux_file'] ) ? |
| 331 |
wp_handle_upload( $_FILES['redux_file'], $upload_overrides ) : |
| 332 |
$file_not_provided_error; |
| 333 |
|
| 334 |
if ( $content_file_info && ! isset( $content_file_info['error'] ) ) { |
| 335 |
$selected_import_files['content'] = $content_file_info['file']; |
| 336 |
} |
| 337 |
else { |
| 338 |
$log_added = self::append_to_file( |
| 339 |
sprintf( |
| 340 |
__( 'Content file was not uploaded. Error: %s', 'borderless' ), |
| 341 |
$content_file_info['error'] |
| 342 |
), |
| 343 |
$log_file_path, |
| 344 |
esc_html__( 'Upload files' , 'borderless' ) |
| 345 |
); |
| 346 |
} |
| 347 |
|
| 348 |
if ( $widget_file_info && ! isset( $widget_file_info['error'] ) ) { |
| 349 |
$selected_import_files['widgets'] = $widget_file_info['file']; |
| 350 |
} |
| 351 |
else { |
| 352 |
$log_added = self::append_to_file( |
| 353 |
sprintf( |
| 354 |
__( 'Widget file was not uploaded. Error: %s', 'borderless' ), |
| 355 |
$widget_file_info['error'] |
| 356 |
), |
| 357 |
$log_file_path, |
| 358 |
esc_html__( 'Upload files' , 'borderless' ) |
| 359 |
); |
| 360 |
} |
| 361 |
|
| 362 |
if ( $customizer_file_info && ! isset( $customizer_file_info['error'] ) ) { |
| 363 |
$selected_import_files['customizer'] = $customizer_file_info['file']; |
| 364 |
} |
| 365 |
else { |
| 366 |
$log_added = self::append_to_file( |
| 367 |
sprintf( |
| 368 |
__( 'Customizer file was not uploaded. Error: %s', 'borderless' ), |
| 369 |
$customizer_file_info['error'] |
| 370 |
), |
| 371 |
$log_file_path, |
| 372 |
esc_html__( 'Upload files' , 'borderless' ) |
| 373 |
); |
| 374 |
} |
| 375 |
|
| 376 |
if ( $redux_file_info && ! isset( $redux_file_info['error'] ) ) { |
| 377 |
if ( isset( $_POST['redux_option_name'] ) && empty( $_POST['redux_option_name'] ) ) { |
| 378 |
self::log_error_and_send_ajax_response( |
| 379 |
esc_html__( 'Missing Redux option name! Please also enter the Redux option name!', 'borderless' ), |
| 380 |
$log_file_path, |
| 381 |
esc_html__( 'Upload files', 'borderless' ) |
| 382 |
); |
| 383 |
} |
| 384 |
|
| 385 |
$selected_import_files['redux'] = array( |
| 386 |
array( |
| 387 |
'option_name' => sanitize_text_field( $_POST['redux_option_name'] ), |
| 388 |
'file_path' => $redux_file_info['file'], |
| 389 |
), |
| 390 |
); |
| 391 |
} |
| 392 |
else { |
| 393 |
$log_added = self::append_to_file( |
| 394 |
sprintf( |
| 395 |
__( 'Redux file was not uploaded. Error: %s', 'borderless' ), |
| 396 |
$redux_file_info['error'] |
| 397 |
), |
| 398 |
$log_file_path, |
| 399 |
esc_html__( 'Upload files' , 'borderless' ) |
| 400 |
); |
| 401 |
} |
| 402 |
|
| 403 |
$log_added = self::append_to_file( |
| 404 |
__( 'The import files were successfully uploaded!', 'borderless' ) . self::import_file_info( $selected_import_files ), |
| 405 |
$log_file_path, |
| 406 |
esc_html__( 'Upload files' , 'borderless' ) |
| 407 |
); |
| 408 |
|
| 409 |
return $selected_import_files; |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
public static function import_file_info( $selected_import_files ) { |
| 414 |
$redux_file_string = ''; |
| 415 |
|
| 416 |
if ( ! empty( $selected_import_files['redux'] ) ) { |
| 417 |
$redux_file_string = array_reduce( $selected_import_files['redux'], function( $string, $item ) { |
| 418 |
return sprintf( '%1$s%2$s -> %3$s %4$s', $string, $item['option_name'], $item['file_path'], PHP_EOL ); |
| 419 |
}, '' ); |
| 420 |
} |
| 421 |
|
| 422 |
return PHP_EOL . |
| 423 |
sprintf( |
| 424 |
__( 'Initial max execution time = %s', 'borderless' ), |
| 425 |
ini_get( 'max_execution_time' ) |
| 426 |
) . PHP_EOL . |
| 427 |
sprintf( |
| 428 |
__( 'Files info:%1$sSite URL = %2$s%1$sData file = %3$s%1$sWidget file = %4$s%1$sCustomizer file = %5$s%1$sRedux files:%1$s%6$s', 'borderless' ), |
| 429 |
PHP_EOL, |
| 430 |
get_site_url(), |
| 431 |
empty( $selected_import_files['content'] ) ? esc_html__( 'not defined!', 'borderless' ) : $selected_import_files['content'], |
| 432 |
empty( $selected_import_files['widgets'] ) ? esc_html__( 'not defined!', 'borderless' ) : $selected_import_files['widgets'], |
| 433 |
empty( $selected_import_files['customizer'] ) ? esc_html__( 'not defined!', 'borderless' ) : $selected_import_files['customizer'], |
| 434 |
empty( $redux_file_string ) ? esc_html__( 'not defined!', 'borderless' ) : $redux_file_string |
| 435 |
); |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
public static function log_error_and_send_ajax_response( $error_text, $log_file_path, $separator = '' ) { |
| 440 |
$log_added = self::append_to_file( |
| 441 |
$error_text, |
| 442 |
$log_file_path, |
| 443 |
$separator |
| 444 |
); |
| 445 |
|
| 446 |
wp_send_json( $error_text ); |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
public static function set_demo_import_start_time() { |
| 451 |
self::$demo_import_start_time = date( self::apply_filters( 'library/date_format_for_file_names', 'Y-m-d__H-i-s' ) ); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
public static function get_all_demo_import_categories( $demo_imports ) { |
| 456 |
$categories = array(); |
| 457 |
|
| 458 |
foreach ( $demo_imports as $item ) { |
| 459 |
if ( ! empty( $item['categories'] ) && is_array( $item['categories'] ) ) { |
| 460 |
foreach ( $item['categories'] as $category ) { |
| 461 |
$categories[ sanitize_key( $category ) ] = $category; |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
if ( empty( $categories ) ) { |
| 467 |
return false; |
| 468 |
} |
| 469 |
|
| 470 |
return $categories; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
public static function get_demo_import_item_categories( $item ) { |
| 475 |
$sanitized_categories = array(); |
| 476 |
|
| 477 |
if ( isset( $item['categories'] ) ) { |
| 478 |
foreach ( $item['categories'] as $category ) { |
| 479 |
$sanitized_categories[] = sanitize_key( $category ); |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
if ( ! empty( $sanitized_categories ) ) { |
| 484 |
return implode( ' ', $sanitized_categories ); |
| 485 |
} |
| 486 |
|
| 487 |
return false; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
public static function set_library_import_data_transient( $data ) { |
| 492 |
set_transient( 'library_importer_data', $data, 0.1 * HOUR_IN_SECONDS ); |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
public static function apply_filters( $hook, $default_data ) { |
| 497 |
$new_data = apply_filters( $hook, $default_data ); |
| 498 |
|
| 499 |
if ( $new_data !== $default_data ) { |
| 500 |
return $new_data; |
| 501 |
} |
| 502 |
|
| 503 |
$old_data = apply_filters( "pt-$hook", $default_data ); |
| 504 |
|
| 505 |
if ( $old_data !== $default_data ) { |
| 506 |
return $old_data; |
| 507 |
} |
| 508 |
|
| 509 |
return $default_data; |
| 510 |
} |
| 511 |
|
| 512 |
public static function do_action( $hook, ...$arg ) { |
| 513 |
if ( has_action( $hook ) ) { |
| 514 |
do_action( $hook, ...$arg ); |
| 515 |
} else if ( has_action( "pt-$hook" ) ) { |
| 516 |
do_action( "pt-$hook", ...$arg ); |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
public static function has_action( $hook, $function_to_check = false ) { |
| 521 |
if ( has_action( $hook ) ) { |
| 522 |
return has_action( $hook, $function_to_check ); |
| 523 |
} else if ( has_action( "pt-$hook" ) ) { |
| 524 |
return has_action( "pt-$hook", $function_to_check ); |
| 525 |
} |
| 526 |
|
| 527 |
return false; |
| 528 |
} |
| 529 |
|
| 530 |
public static function get_plugin_page_setup_data() { |
| 531 |
return Helpers::apply_filters( 'library/plugin_page_setup', array( |
| 532 |
'parent_slug' => 'borderless.php', |
| 533 |
'page_title' => esc_html__( 'Library' , 'borderless' ), |
| 534 |
'menu_title' => esc_html__( 'Library' , 'borderless' ), |
| 535 |
'capability' => 'import', |
| 536 |
'menu_slug' => 'borderless-library', |
| 537 |
) ); |
| 538 |
} |
| 539 |
} |
| 540 |
|