-
Notifications
You must be signed in to change notification settings - Fork 1
/
private-media.php
executable file
·65 lines (51 loc) · 2.05 KB
/
private-media.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
Plugin Name: Private Media
Plugin URI: https://github.com/froger-me/private-media/
Text Domain: pvtmed
Description: Add access restrictions to specific items of the WordPress Media Library.
Version: 1.11
Author: Alexandre Froger, <a href="https://appamics.com">Christoph Bratschi</a>
Author URI: https://froger.me/
GitHub Plugin URI: https://github.com/cbratschi/private-media
Requires at least: 4.9.8
Tested up to: 6.7.1
Requires PHP: 8.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! defined( 'PVTMED_PLUGIN_PATH' ) ) {
define( 'PVTMED_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'PVTMED_PLUGIN_URL' ) ) {
define( 'PVTMED_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once PVTMED_PLUGIN_PATH . 'inc/class-private-media.php';
require_once PVTMED_PLUGIN_PATH . 'inc/class-private-media-attachment-manager.php';
register_activation_hook( __FILE__, array( 'Private_media', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'Private_media', 'deactivate' ) );
register_uninstall_hook( __FILE__, array( 'Private_media', 'uninstall' ) );
/**
* Execute plugin.
*/
function pvtmed_run() {
require_once PVTMED_PLUGIN_PATH . 'inc/class-private-media-request-handler.php';
$request_handler = new Private_Media_Request_Handler();
$attachment_manager = new Private_Media_Attachment_Manager( true );
$pvtmed = new Private_Media( $request_handler, $attachment_manager, true );
}
add_action( 'plugins_loaded', 'pvtmed_run', 10, 0 );
//run migration scripts
if ( ! Private_media::is_doing_api_request() ) {
require_once plugin_dir_path( __FILE__ ) . 'lib/wp-update-migrate/class-wp-update-migrate.php';
add_action( 'plugins_loaded', function() {
$pvtmed_update_migrate = WP_Update_Migrate::get_instance( __FILE__, 'pvtmed' );
if ( false === $pvtmed_update_migrate->get_result() ) {
if ( false !== has_action( 'plugins_loaded', 'pvtmed_run' ) ) {
remove_action( 'plugins_loaded', 'pvtmed_run', 10 );
}
}
}, PHP_INT_MIN );
}