WordPress.org

Ready to get started?Download WordPress

Forums

WP Photo Album Plus
[resolved] multisite support switch local to global [set option request] (10 posts)

  1. lancelot-du-lac
    Member
    Posted 1 year ago #

    Hello and congratulations for your excellent plugin

    Your frequent upgrade with wp-photo-album-plus forces me to make each times a small patch on the script wppa.php.
    It is important for me to have plugins updated.

    So, thank you for your work and activity on the plugin.

    In fact, I use the main table as global table for the entire blog network.

    For this, I change the value ($ wpdb-> prefix) to ($ wpdb-> base_prefix) and redefines the download variables for blogs as global too.

    This creates, I think a good plugin option for your multisite support.

    To see the patch in action:
    All Albums network are displayed on the main site:
    http://www.cieuxinternational.org/fr/media/albums/

    The album can be seen locally on the corresponding blog:
    http://www.cieuxinternational.org/paris-10/fr/album/

    For the principle I have to create an album for each blog and call this category via %%album=album_id_for_the_blog%% in the WP blog page dedicated to the local album.

    Of course, on each blog admin albums all the the network is also available (which is a bit confusing).

    In fact it could be very simple to define on each parent album if is:
    - Global (sitewide), in this case we use $ wpdb-> base_prefix.
    - Local (strictly), in this case we use $ wpdb-> prefix.

    In my case all albums are global so I just need to have authority over the table to use.

    // REQUEST

    Would it be possible to integrate a filter on the table name in wppa.php as an early option to support multi-site global or local.

    Something like that :

    /**************** wppa.php, line 34 *************/
    /* some add_option to create somewhere on init */
    add_option('wppa_switch_to','local'); // default to 'local' for keep compatibilty with prev versions..
    // each blog administrator decides
    //or better
    add_site_option('wppa_switch_to','local'); //
    // main site adminstrator decides

    /* some update_option to set somewhere on admin, according to add */
    update_option('wppa_switch_to','global');
    update_site_option('wppa_switch_to','local');

    /**
    It is clear that when the choice between global and local is done, the backward becomes destructive.
    Two solutions: disable update_options or update_site_option when albums are filled (to test) or preventive message, in case of change, that all is lost and do it again.**/
    /**
    Later see how this can be set for each parent album whose belong or not with a particular blog... this can be a bit difficult. Full global, or full local is a simple way... why not?
    **/
    /************************************************/
    add_filter('wppa_switch_table', 'wppa_switch_to');
    function wppa_switch_to($switch) {
    global $wpdb;
    if($switch=='global') {
    return $wpdb->base_prefix;
    } else {
    return $wpdb->prefix;
    }
    }
    $wppa_switch=get_site_option('wppa_switch_to'); // or get_option
    $wppa_table_prefix = apply_filters('wppa_switch_table',$wppa_switch);
    /**
    Use $wppa_switch [global|local] in 'wppa-common-functions.php' on line 481 for global mode

    if ( is_multisite() && $wppa_switch== 'local) {
    ...

    **/
    define( 'WPPA_ALBUMS', $wppa_table_prefix . 'wppa_albums' );
    define( 'WPPA_PHOTOS', $wppa_table_prefix . 'wppa_photos' );
    define( 'WPPA_RATING', $wppa_table_prefix . 'wppa_rating' );
    define( 'WPPA_COMMENTS', $wppa_table_prefix . 'wppa_comments' );
    define( 'WPPA_IPTC', $wppa_table_prefix . 'wppa_iptc' );
    define( 'WPPA_EXIF', $wppa_table_prefix . 'wppa_exif' );

    /**** start again with define('WPPA_FILE' ... ****/

    ///////////////

    Subsidiary note: The stars of evaluation are not clickable (tested on chrome & safari Mac Os). Even though I'm well connected ... buddypress account. I haven't taken times to see why.

    http://wordpress.org/support/plugin/wp-photo-album-plus

    http://wordpress.org/extend/plugins/wp-photo-album-plus/

  2. Jacob N. Breetvelt
    Member
    Plugin Author

    Posted 1 year ago #

    This topic is being studied at the moment, i will come back on it later.

    Subsidiary note: The stars of evaluation are not clickable (tested on chrome & safari Mac Os). Even though I'm well connected ... buddypress account. I haven't taken times to see why.

    Please open a new thread for this, and either supply me login name and pw ( send to opajaap at opajaap dot nl ) or uncheck Table IV-E1.

  3. lancelot-du-lac
    Member
    Posted 1 year ago #

    great!

    for the stars I would try to look more closely before calling the cavalry. I like the investigative work, and archeology of programming. :) ... It was just to talk.

  4. Jacob N. Breetvelt
    Member
    Plugin Author

    Posted 1 year ago #

    About your request:

    The idea to have this feature optional is attractive.

    • The idea to have it - more or less - switcheable is difficult. A simple setting in an option or global option is too dangerous; as you stated before switching when there are albums/photos is disastrous.
    • The idea for a filter/action is also dangerous. Many themes and plugins mess around with removing actions and filters.
    • The idea to make individual blogadmins to decide to go either local or global is also dangerous. There will be duplicate id's in the tables and sooner or later this will cause serious trouble.
    • The switch is rather simple to implement.

    My suggestion, that will be insensitive to updates and difficult to destructify by admins or users:

    Add in wp-config:

    define ('WPPA_MULITSITE_GLOBAL', true);

    I can detect in 'wppa.php' and 'wppa-common-functions.php' if this define is set and true, and 'go for' the base_prefix and the singlesite choice for the path and url defines.

    Isn't it simple?

    Please your reply on this suggestion

  5. lancelot-du-lac
    Member
    Posted 1 year ago #

    great for me ...

    I adapt my patch with this variable.

    I just had a serious breakdown on my main computer - which confirms my disastrous September.
    As soon as I get back to normal, I'll operational testing this with you.

  6. Jacob N. Breetvelt
    Member
    Plugin Author

    Posted 1 year ago #

    I will supply the codechanges to make.

  7. Jacob N. Breetvelt
    Member
    Plugin Author

    Posted 1 year ago #

    Here is the patch. If it works it will be standard code.

    1. In wppa.php at line 33 change:

    define( 'WPPA_ALBUMS',   $wpdb->prefix . 'wppa_albums' );
    define( 'WPPA_PHOTOS',   $wpdb->prefix . 'wppa_photos' );
    define( 'WPPA_RATING',   $wpdb->prefix . 'wppa_rating' );
    define( 'WPPA_COMMENTS', $wpdb->prefix . 'wppa_comments' );
    define( 'WPPA_IPTC',	 $wpdb->prefix . 'wppa_iptc' );
    define( 'WPPA_EXIF', 	 $wpdb->prefix . 'wppa_exif' );

    into:

    /* To run WPPA+ on a multisite in single site mode, add to wp-config.php: define('WPPA_MULITSITE_GLOBAL', true); */
    if ( ! defined('WPPA_MULITSITE_GLOBAL') ) define ('WPPA_MULITSITE_GLOBAL', false);
    if ( is_multisite() && WPPA_MULITSITE_GLOBAL ) $wppa_prefix = $wpdb->base_prefix; else $wppa_prefix = $wpdb->prefix;
    define( 'WPPA_ALBUMS',   $wppa_prefix . 'wppa_albums' );
    define( 'WPPA_PHOTOS',   $wppa_prefix . 'wppa_photos' );
    define( 'WPPA_RATING',   $wppa_prefix . 'wppa_rating' );
    define( 'WPPA_COMMENTS', $wppa_prefix . 'wppa_comments' );
    define( 'WPPA_IPTC',	 $wppa_prefix . 'wppa_iptc' );
    define( 'WPPA_EXIF', 	 $wppa_prefix . 'wppa_exif' );

    2. In wppa-common-functions.php at line 480 change:

    if ( ! defined( 'WPPA_UPLOAD') ) {
    	if ( is_multisite() ) {

    into:

    if ( ! defined( 'WPPA_UPLOAD') ) {
    	if ( is_multisite() && ! WPPA_MULITSITE_GLOBAL ) {
  8. lancelot-du-lac
    Member
    Posted 1 year ago #

    work fine, thank

  9. Jacob N. Breetvelt
    Member
    Plugin Author

    Posted 1 year ago #

    @lancelot-du-lac

    !!!IMPORTANT NOTICE!!!

    There is a typo in the above. It reads WPPA_MULITSITE_GLOBAL where it should be WPPA_MULTISITE_GLOBAL

    Please be aware that the next version will have the correct semantics.

    PLEASE respond that you have read this

  10. lancelot-du-lac
    Member
    Posted 1 year ago #

    ok, I read and I check this. Thanks for the caution alert.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic