class-admin.php 8.53 KB
Newer Older
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
<?php
/**
 * Copyright: 2022 (c)Franco (nextime) Lanza <franco@nexlab.it>
 * License: GNU/GPL version 3.0
 *
 * This file is part of SexHackMe Wordpress Plugin.
 *
 * SexHackMe Wordpress Plugin is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published 
 * by the Free Software Foundation, either version 3 of the License, 
 * or (at your option) any later version.
 *
 * SexHackMe Wordpress Plugin is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
 * along with SexHackMe Wordpress Plugin. If not, see <https://www.gnu.org/licenses/>.
 */

namespace wp_SexHackMe;

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;


if(!class_exists('SH_Admin')) {
   class SH_Admin
   {

      public static function init()
      {
34
         // Add general settings section     
35 36
         add_settings_section('sexhackme-settings', ' ', 'wp_SexHackMe\sexhackme_settings_section', 'sexhackme-settings');

37 38 39 40 41 42 43
         // Add General settings section
         if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-sexhackme.php') )
         {
            include_once(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-sexhackme.php');
            register_setting('sexhackme-settings', 'sexhack-model-role');
         }

44
         // Add WC-PMS_Integration settings
45 46
         if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-wcpms.php') )
         {
47 48 49 50 51 52 53 54 55 56
            include_once SH_PLUGIN_DIR_PATH . 'includes/admin/functions-wcpms.php';
            $plans = sh_get_subscription_plans();
            add_settings_section('sexhackme-wcpms-settings', ' ', 'wp_SexHackMe\settings_wcpms_section', 'sexhackme-wcpms-settings');
            register_setting('sexhackme-wcpms-settings', 'sexhack-wcpms-checkout');
            foreach($plans as $plan)
            {
               if($plan->price > 0)
               {
                  register_setting('sexhackme-wcpms-settings', 'sexhack-wcpms-'.strval($plan->id));
               }
57 58 59
            }
            add_settings_section('sexhackme-wcpms-settings', ' ', 'wp_SexHackMe\settings_wcpms_section_email', 'sexhackme-wcpms-settings-email');
            register_setting('sexhackme-wcpms-settings', 'sexhack_registration_mail_endpoint');
60 61 62 63 64 65

            add_settings_section('sexhackme-wcpms-settings', ' ', 'wp_SexHackMe\settings_wcpms_section_prodcat', 'sexhackme-wcpms-settings-prodcat');
            register_setting('sexhackme-wcpms-settings', 'sexhack_wcpms-prodcat');
            register_setting('sexhackme-wcpms-settings', 'sexhack_wcpms-prodvisible');


66
         }
67 68 69 70 71

         // Add Advertising settings
         if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-advert.php') )
         {
            include_once SH_PLUGIN_DIR_PATH . 'includes/admin/functions-advert.php';
72
            add_settings_section('sexhackme-advert-settings', ' ', 'wp_SexHackMe\settings_advert_section', 'sexhackme-advert-settings');
73
            register_setting('sexhackme-advert-settings', 'sexadv_video_top');
74
            register_setting('sexhackme-advert-settings', 'sexadv_video_bot');
75
         }
76 77 78 79 80

         // Gallery settings
         if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-gallery.php') )
         {
             include_once SH_PLUGIN_DIR_PATH . 'includes/admin/functions-gallery.php';
81
             add_settings_section('sexhackme-gallery-settings', ' ','wp_SexHackMe\gallery_settings_section', 'sexhackme-gallery-settings');
82 83 84 85 86
             register_setting('sexhackme-gallery-settings', 'sexhack_video_page');
             register_setting('sexhackme-gallery-settings', 'sexhack_gallery_page');
             register_setting('sexhackme-gallery-settings', 'sexhack_video404_page');
             add_action('update_option', '\wp_SexHackMe\SH_Admin::update_gallery_slug', 10, 3);
             //register_setting('sexhackme-gallery-settings', 'sexhack_gallery_slug');
87
         }
88 89

         // RClone settings
90 91 92 93 94 95 96 97
         if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-rclone.php') )
         {
            include_once SH_PLUGIN_DIR_PATH . 'includes/admin/functions-rclone.php';
            add_settings_section('sexhackme-rclone-settings', ' ','wp_SexHackMe\rclone_settings_section', 'sexhackme-rclone-settings');
            register_setting('sexhackme-rclone-settings', 'sexhack_rclone_path'); 
            register_setting('sexhackme-rclone-settings', 'sexhack_rclone_gdrive_name'); 
            register_setting('sexhackme-rclone-settings', 'sexhack_rclone_gdrive_shared');
         }
98 99
      }

100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
      public static function update_gallery_slug($option, $old, $new)
      {
         switch($option)
         {
            case 'sexhack_video_page':
               if(!is_int($new)) break;
               $page = get_post($new);
               set_option('sexhack_gallery_slug', $page->post_name);
               update_option('need_rewrite_flush', 1);
               break;

            case 'sexhack_gallery_page':
               update_option('need_rewrite_flush', 1);
               break;
            case 'sexhack_video404_page':
               update_option('need_rewrite_flush', 1);
               break;


            default:
               break;
         }


      }

126 127
      public static function menu()
      {
128

129 130
         add_menu_page('SexHackMe Settings', 'SexHackMe', 'manage_options', 'sexhackme-settings',
               'wp_SexHackMe\sexhackme_admin_page', SH_PLUGIN_DIR_URL .'img/admin_icon.png', 31);
131

132
         // Add The main page again cause with multiple subpages apparently we need to do it.
133
          add_submenu_page( 'sexhackme-settings', 'SexHackMe Settings', 'General Settings',
134 135
                  'manage_options', 'sexhackme-settings');

136
         // TODO We don't have a main page yet, so, remove it.
137
         //remove_submenu_page( 'sexhackme-settings', 'sexhackme-settings' );
138 139


140 141 142 143 144 145 146 147
         // Add Gallery settings page
         if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-gallery.php') )
         {
               add_submenu_page( 'sexhackme-settings',             // root slug
                           'Gallery',                              // title
                           'Gallery',                              // title
                           'manage_options',                       // capabilities
                           'gallery',                              // slug
148 149
                           'wp_SexHackMe\gallery_adminpage',       // callback
                           20);
150 151

         }
152

153 154 155 156 157 158 159 160
         // Add RClone interface
         if (file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-rclone.php') )
         {
               add_submenu_page( 'sexhackme-settings',
                           'RClone',
                           'RClone',
                           'manage_options',
                           'rclone',
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
                           'wp_SexHackMe\rclone_adminpage',
                           50);
         }

         // Add page WC-PMS_Integration
         if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-wcpms.php') )
         {

               add_submenu_page( 'sexhackme-settings',             // root slug
                           'WC-PMS Integration',                   // title
                           'WC-PMS Integration',                   // title
                           'manage_options',                       // capabilities
                           'pmswc-integration',                    // slug
                           'wp_SexHackMe\wcpms_adminpage',         // callback
                           60);                                    // position
         }

         // Add Advertising settings
         if( file_exists(SH_PLUGIN_DIR_PATH . 'includes/admin/functions-advert.php') )
         {
               add_submenu_page( 'sexhackme-settings',            // root slug
                           'Advertising',                         // title
                           'Advertising',                         // title
                           'manage_options',                      // capabilities
                           'advert',                              // slug
                           'wp_SexHackMe\advert_adminpage',       // callback
                           80);

189 190
         }

191 192 193 194
         // Add Video tags and categories subpages to Video edit menu
         //if(in_array('sexhack_video', get_post_types())
         //{
         //}
195 196 197 198 199 200 201
      }

   }
}


?>