"; } function fivecentscdn_add_toolbar_items($admin_bar) { $current_page = admin_url(sprintf('admin.php?%s', http_build_query($_GET))); if (strpos($current_page, 'action=edit') !== false) { $url_components = parse_url($current_page); parse_str($url_components['query'], $params); $post_id = $params['post']; $post_data = (array) get_post($post_id); $post_slug_name = $post_data['post_name']; $page_url = esc_url(get_post_type_archive_link('post')).'/'.$post_slug_name; $admin_bar->add_menu( array( 'id' => 'fivecentscdn-sub-item-purge-single', 'parent' => 'fivecentscdn', 'title' => 'Post/Page Purge', 'href' =>admin_url('admin.php?page=5centscdn&purge="file"&file_url='.$page_url), 'meta' => array( 'title' => __('Post/Page Purge'), 'target' => '_blank', 'class' => 'wp_rocket_item' ), )); } $options = FivecentsCDN::getOptions(); if ($options['wp_disble_cdn'] == '1' || $options['asset_acceleration'] == '1') { $head_cdn_status_text="Disable CDN"; $cdn_switch_status=0; } else { $head_cdn_status_text="Enable CDN"; $cdn_switch_status=1; } $admin_bar->add_menu( array( 'id' => 'fivecentscdn', 'title' => '5centscdn', 'href' => '#', 'meta' => array( 'title' => __('My Item'), ), )); $admin_bar->add_menu( array( 'id' => 'fivecentscdn-sub-item-setting', 'parent' => 'fivecentscdn', 'title' => 'Setting', 'href' =>admin_url('admin.php?page=5centscdn'), 'meta' => array( 'title' => __('Setting'), 'target' => '', 'class' => 'wp_rocket_item' ), )); $admin_bar->add_menu([ 'id' => 'disable-fivecentscdn', 'parent' => 'fivecentscdn', 'title' => $head_cdn_status_text, 'href' => wp_nonce_url(admin_url('admin.php?page=5centscdn&wp_disble_cdn='.$cdn_switch_status)) ]); $admin_bar->add_menu( array( 'id' => 'fivecentscdn-sub-item-purge-all', 'parent' => 'fivecentscdn', 'title' => 'Purge All', 'href' => admin_url('admin.php?page=5centscdn&purge="all"'), 'meta' => array( 'title' => __('Purge All'), 'target' => '_blank', 'class' => 'wp_rocket_item' ), )); $admin_bar->add_menu( array( 'id' => 'fivecentscdn-sub-faq', 'parent' => 'fivecentscdn', 'title' => 'FAQ', 'href' =>"https://www.5centscdn.net/help/?s=wordpress", 'meta' => array( 'title' => __('FAQ'), 'target' => '_blank', 'class' => 'wp_rocket_item' ), )); } function fivecentscdn_disable_editor_fullscreen_by_default() { $script = "jQuery( window ).load(function() { const isFullscreenMode = wp.data.select( 'core/edit-post' ).isFeatureActive( 'fullscreenMode' ); if ( isFullscreenMode ) { wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'fullscreenMode' ); } });"; wp_add_inline_script( 'wp-blocks', $script ); } function fivecentscdn_cname_update() { $api_key=$_POST['apikey']; $zoneid=$_POST['zoneid']; $orgin=$_POST['orgin']; $cnames=$_POST['cnames']; if (isset($_POST['apikey'])) { $api = new FivecentsCDNApi(); $zoneArr = $api->updatePullZoneCname($zoneid,sanitize_text_field($api_key),$orgin,$cnames); echo json_encode($zoneArr); } wp_die(); } function fivecentscdn_do_rewrite() { $options = FivecentsCDN::getOptions(); if ($options['wp_disble_cdn'] == 1 || $options['asset_acceleration'] == 1) { if (strlen(trim($options["cdn_domain_name"])) > 0) { $modified_site_url = $options["site_url"]; if (!str_contains($options["site_url"], 'https') && isset($_SERVER['HTTPS'])) { $modified_site_url = str_replace("http://", "https://", $modified_site_url); } $rewriter = new FivecentsCDNFilter( $modified_site_url, "https://" . $options["cdn_domain_name"], $options["directories"], $options["excluded"], $options["disable_admin"] ); $rewriter->startRewrite(); } } } function fivecentscdn_update_zone_ssl() { if (isset($_POST['apikey'])) { $zoneid = $_POST['zoneid']; $api_key = $_POST['apikey']; $http2 = $_POST['http2']; $redirect = $_POST['redirect']; $mode = $_POST['mode']; $enabled = $_POST['enabled']; $options = FivecentsCDN::getOptions(); $options['https'] = ($enabled == 'Y'); update_option('5centscdn', $options); $api = new FivecentsCDNApi(); $zonessl = $api->updatePullZoneSsl($zoneid,sanitize_text_field($api_key),$http2,$redirect,$mode,$enabled); echo json_encode($zonessl); } wp_die(); } function fivecentscdn_dnsPrefetch() { $options = FivecentsCDN::getOptions(); if(strlen(trim($options["cdn_domain_name"])) > 0) { echo ""; } } function fivecentscdn_purge() { $options = FivecentsCDN::getOptions(); $api = new FivecentsCDNApi(); if (strlen(trim($options["cdn_domain_name"])) > 0) { $purge_res = $api->purgePullZone($options["pull_zone"], $options["api_key"]); echo json_encode($purge_res); } wp_die(); } function fivecentscdn_purge_file() { $options = FivecentsCDN::getOptions(); $api = new FivecentsCDNApi(); if(strlen(trim($options["cdn_domain_name"])) > 0) { $post_url = $_POST['post_url']; $purge_res = $api->purgePullZoneFile($options["pull_zone"], $options["api_key"], $post_url); echo json_encode($purge_res); } wp_die(); } function fivecentscdn_zone() { $api = new FivecentsCDNApi(); if (isset($_POST['zone_id']) && isset($_POST['apikey'])) { $zoneArr = $api->getPullZones((int)($_POST['zone_id']), sanitize_text_field($_POST["apikey"])); $data = [ 'http' => $zoneArr['zone']['ssl']['http2'], 'serviceid' => $zoneArr['zone']['serviceid'], 'enabled' => $zoneArr['zone']['ssl']['enabled'], 'cnames' => $zoneArr['zone']['cnames'], 'fqdn' => $zoneArr['zone']['fqdn'], 'warning' => $zoneArr['zone']['ssl']['warning'], ]; echo json_encode($data); } wp_die(); } function fivecentscdn_all_zones() { if (isset($_POST['apikey'])) { $api = new FivecentsCDNApi(); $zoneArr = $api->listPullZones(sanitize_text_field($_POST['apikey'])); if (count($zoneArr['zones']) > 0) { $data = []; foreach ($zoneArr['zones'] as $key => $value) { if ($value['status'] != "Deleted" && $value['optimize'] == 'http') { $data[] = [ "id" => $value['id'], "name" => "HTTP Pull #{$value['id']}".($value['alias'] ? " ({$value['alias']})" : ''), "serviceid" => $value['serviceid'], ]; } } if (count($data) > 0) { echo json_encode($data); } } } wp_die(); } function fivecentscdn_promotional_banner() { if (!isset($_COOKIE['fivecentscdn_banner_closed'])) { $banner_image_url = plugins_url('assets/5centscdn.png', __FILE__ ); echo '

Hey! You have been using 5centsCDN Plugin for a few days and we hope 5centsCDN is able to help you speed up your Assets & Website Delivery. If you like our plugin would you please show some love by doing actions like :

'; } } function fivecentscdn_deleteoption() { delete_option('5centscdn'); } ?>