Plugin Directory

Changeset 3052723


Ignore:
Timestamp:
03/17/2024 03:24:44 PM (2 years ago)
Author:
vpelss
Message:

playground fix #5

Location:
emogics-tarot-reader-for-wp/tags/0.8.1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • emogics-tarot-reader-for-wp/tags/0.8.1/Emogic Tarot Reader Plugin for Wordpress.php

    r3052160 r3052723  
    11<?php
    22/**
    3 * Plugin Name: Emogic Tarot Reader
     3* Plugin Name: Emogic Tarot Reader Plugin for Wordpress
    44* Plugin URI: https://github.com/vpelss/Emogics_Tarot_Script_WP#readme
    5 * Description: Emogic Tarot Reader Plugin for Wordpress
     5* Description: Emogic Tarot Reader
    66* Version: 0.8.1
    77* License: GPLv3
     
    1818   
    1919   define( 'EMOGIC_TAROT_PLUGIN_LOCATION_URL', plugins_url('/' , __FILE__) ); // http://wp_url/wp-content/plugins/Emogic Tarot Reader Plugin for Wordpress/
    20    define( 'EMOGIC_TAROT_PLUGIN_NAME' , plugin_basename( __FILE__ ) ); // Emogic Tarot Reader Plugin for Wordpress (or other if renamed)
     20   define( 'EMOGIC_TAROT_RELATIVE_PLUGIN_PATH' , plugin_basename( __FILE__ ) ); // Emogic Tarot Reader Plugin for Wordpress (or other if renamed)
     21   define( 'EMOGIC_TAROT_PLUGIN_DIR_BASENAME' , basename( dirname( __FILE__ ) ) ); // Emogic-Tarot-Reader-Plugin-for-Wordpress unless changed
    2122   define( 'EMOGIC_TAROT_PLUGIN_WP_ROOT_URL' , home_url() ); // http://wp_url/
    2223   //same as folder structure under /pages/ in plugin
  • emogics-tarot-reader-for-wp/tags/0.8.1/admin/EmogicTarotReader_Admin.php

    r3052019 r3052723  
    1212        add_action( 'admin_menu', 'EmogicTarotReader_Admin::create_admin_page_and_slug' );
    1313        //set up 'settings' link in plugin menu
    14         add_filter( "plugin_action_links_" . EMOGIC_TAROT_PLUGIN_NAME , 'EmogicTarotReader_Admin::create_plugin_setting_link' );
     14        add_filter( "plugin_action_links_" . EMOGIC_TAROT_RELATIVE_PLUGIN_PATH , 'EmogicTarotReader_Admin::create_plugin_setting_link' );
    1515    }
    1616   
  • emogics-tarot-reader-for-wp/tags/0.8.1/inc/EmogicTarotReader_Activator.php

    r3052019 r3052723  
    1111class EmogicTarotReader_Activator{
    1212   
    13     public static function activate(){ 
     13    public static function activate(){
     14       
     15        $upload_array = wp_upload_dir();
     16        DEFINE( 'EMOGIC_TAROT_PLUGIN_UPLOADS_PATH' , $upload_array['basedir'] );
     17       
     18        add_option(EMOGIC_TAROT_PLUGIN_EMAIL_SUBJECT_OPTION , 'Tarot Reading');
     19       
    1420        self::read_and_create_pages();
    15         self::images_to_media_library();
    16         add_option(EMOGIC_TAROT_PLUGIN_EMAIL_SUBJECT_OPTION , 'Tarot Reading');
     21       
     22        //$pth = 'wp-content/plugins/' . EMOGIC_TAROT_PLUGIN_DIR_BASENAME . '/images';
     23        //define( 'UPLOADS',  $pth  );
     24       
     25        //https://wordpress.stackexchange.com/questions/222540/change-wordpress-upload-path-and-url
     26        //add_filter( 'pre_option_upload_path', ["EmogicTarotReader_Activator" , "upload_path"] );
     27        //add_filter( 'pre_option_upload_url_path', ["EmogicTarotReader_Activator" , "upload_url_path"] );
     28
     29        //disable thumbnails : https://perishablepress.com/disable-wordpress-generated-images/
     30        add_action('intermediate_image_sizes_advanced', ['EmogicTarotReader_Activator' , 'shapeSpace_disable_image_sizes'] );
     31        add_action('init', ['EmogicTarotReader_Activator' , 'shapeSpace_disable_other_image_sizes']);
     32        add_filter('big_image_size_threshold', '__return_false'); // disable scaled image size
     33
     34        try{
     35            self::images_to_media_library();
     36        }
     37        catch(Exception $e){
     38            //ignore for sake of wp playground. It does not like copy functions, etc
     39        }
     40       
     41        //remove_filter( 'pre_option_upload_path', self::upload_path );
     42        //remove_filter( 'pre_option_upload_path', self::upload_url_path );
     43       
    1744        flush_rewrite_rules();
    1845    }
     46   
     47    // disable generated image sizes
     48    public static function shapeSpace_disable_image_sizes($sizes) {
     49        unset($sizes['thumbnail']);    // disable thumbnail size
     50        unset($sizes['medium']);       // disable medium size
     51        unset($sizes['large']);        // disable large size
     52        unset($sizes['medium_large']); // disable medium-large size
     53        unset($sizes['1536x1536']);    // disable 2x medium-large size
     54        unset($sizes['2048x2048']);    // disable 2x large size
     55        return $sizes;
     56    }
     57
     58    // disable other image sizes
     59    public static function shapeSpace_disable_other_image_sizes() {
     60        remove_image_size('post-thumbnail'); // disable images added via set_post_thumbnail_size()
     61        remove_image_size('another-size');   // disable any other added image sizes
     62    }
     63
     64    //https://developer.wordpress.org/reference/functions/wp_upload_dir/
     65    /*
     66    Checks the ‘upload_path’ option, which should be from the web root folder, and if it isn’t empty it will be used.
     67    If it is empty, then the path will be ‘WP_CONTENT_DIR/uploads’.
     68    If the ‘UPLOADS’ constant is defined, then it will override the ‘upload_path’ option and ‘WP_CONTENT_DIR/uploads’ path.
     69
     70    The upload URL path is set either by the ‘upload_url_path’ option or by using the ‘WP_CONTENT_URL’ constant and appending ‘/uploads’ to the path.
     71   
     72    If the ‘uploads_use_yearmonth_folders’ is set to true (checkbox if checked in the administration settings panel), then the time will be used. The format will be year first and then month.
     73   
     74    If the path couldn’t be created, then an error will be returned with the key ‘error’ containing the error message. The error suggests that the parent directory is not writable by the server.
     75    */
     76   
     77    public static function upload_path(){
     78        $pth = 'wp-content/plugins/' . EMOGIC_TAROT_PLUGIN_DIR_BASENAME . '/images';
     79        return $pth;
     80    }
     81   
     82    public static function upload_url_path(){
     83        $pth = EMOGIC_TAROT_PLUGIN_WP_ROOT_URL . '/';
     84        return $pth ;
     85    }
     86   
    1987   
    2088    public static function read_and_create_pages(){
     
    81149   
    82150    public static function images_to_media_library(){
     151        //throw new Exception("test throw");
    83152        $deactivate_media_array = array();     
    84         $from = EMOGIC_TAROT_PLUGIN_PATH . "images";
    85         $to = ABSPATH . "wp-content/uploads/" .EMOGIC_TAROT_PLUGIN_MEDIA_FOLDER ;
    86                
    87         @mkdir($to, 0755); //create dest dir
    88         self::recursive_copy($from , $to , $deactivate_media_array); //copy files       
     153        $from = EMOGIC_TAROT_PLUGIN_PATH . 'images/';
     154        $to = EMOGIC_TAROT_PLUGIN_UPLOADS_PATH . '/' . EMOGIC_TAROT_PLUGIN_MEDIA_FOLDER ;
     155        $sub_path = '';
     156       
     157        self::recursive_copy($from , $to , $sub_path , $deactivate_media_array); //copy files       
    89158        add_option( EMOGIC_TAROT_PLUGIN_MEDIA_ARRAY_OPTION , array_reverse($deactivate_media_array));   
    90159    }
    91160   
    92     public static function recursive_copy($src , $dst , &$deactivate_media_array) { //$src and $dst do not have lagging slashes
     161    public static function recursive_copy($src , $dst , $sub_path , &$deactivate_media_array) { //$src and $dst do not have lagging slashes
    93162        $dir = opendir($src);
    94         @mkdir($dst); 
     163        @mkdir($dst);       
    95164        while(false !== ( $file = readdir($dir)) ) {
    96             if (( $file != '.' ) && ( $file != '..' )) {
    97                 if ( is_dir($src . '/' . $file) ) {
    98                     self::recursive_copy($src . '/' . $file, $dst  . '/' . $file , $deactivate_media_array );
     165            if (( $file != '.' ) && ( $file != '..' )) {
     166                $src_path_and_file = $src . '/' . $file;
     167                $dst_path_and_file = $dst . '/' . $file;
     168                $sub_path_and_file = $sub_path . '/' . $file;
     169                if ( is_dir($src_path_and_file) ) {
     170                    self::recursive_copy($src_path_and_file , $dst_path_and_file ,  $sub_path_and_file , $deactivate_media_array );
    99171                }
    100             if ( is_file($src . '/' . $file) )  {
    101                     copy($src . '/' . $file , $dst . '/' . $file);
    102                     self::copy_image_to_media_library($dst . '/' . $file , $file , $deactivate_media_array);
     172            if ( is_file($src_path_and_file) )  {
     173                    @copy( $src_path_and_file , $dst_path_and_file);
     174                    self::copy_image_to_media_library($dst_path_and_file , $file , $deactivate_media_array,  $sub_path_and_file );
    103175                }
    104176            }
     
    107179    }
    108180
    109     public static function copy_image_to_media_library($file_path , $filename , &$deactivate_media_array){           
    110             $artdata = array(
     181    public static function copy_image_to_media_library($path_and_file , $filename , &$deactivate_media_array , $subpath_and_file){
     182   
     183        $artdata = array(
    111184                'post_author' => 1,
    112185                'post_title' => $filename,
     
    117190                'post_parent' => 0,
    118191                'post_type' => 'attachment',
    119                 'guid' => $file_path,
     192                //'guid' => $file_path,
    120193                'post_mime_type' => 'image/jpg',
    121194                'post_excerpt' => $filename,
    122195                'post_content' => $filename,
    123                 'size'     => filesize( $file_path ),
     196                'size'     => filesize( $path_and_file ),
    124197            );
    125             $attach_id = wp_insert_attachment( $artdata , $file_path , 0);
     198           
     199            $target_subpath_and_file = EMOGIC_TAROT_PLUGIN_MEDIA_FOLDER . $subpath_and_file;
     200            $attach_id = wp_insert_attachment( $artdata , $target_subpath_and_file , 0);
    126201   
    127202            //generate metadata and thumbnails
    128             if ($attach_data = wp_generate_attachment_metadata( $attach_id , $file_path)) {
     203            if ($attach_data = wp_generate_attachment_metadata( $attach_id , $path_and_file)) {
    129204                wp_update_attachment_metadata($attach_id , $attach_data);
    130205            }
    131206            array_push( $deactivate_media_array , $attach_id );
     207
    132208    }
    133209   
  • emogics-tarot-reader-for-wp/tags/0.8.1/readme.txt

    r3052163 r3052723  
    5555== Changelog ==
    5656= 0.8.1 =
    57 Playground friendly
     57Attempt to make playground friendly
    5858
     59== Upgrade Notice ==
    5960= 0.8.0 =
    6061* Initial release.
    61 
    62 == Upgrade Notice ==
    63 = 0.8.1 =
    64 Playground friendly
Note: See TracChangeset for help on using the changeset viewer.