Plugin Directory

Changeset 3423195


Ignore:
Timestamp:
12/18/2025 07:10:59 PM (4 months ago)
Author:
rainbowslider
Message:

version: 1.0.4 - template support (theme/elementor full with/canva)

Location:
rainbow-slider/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rainbow-slider/trunk/rainbow-slider.php

    r3423134 r3423195  
    44 * Plugin URI:        https://wordpress.org/plugins/rainbow-slider/
    55 * Description:       Convert Elementor Sections, Containers, and Grids into a responsive Slider effortlessly.
    6  * Version:           1.0.3
     6 * Version:           1.0.4
    77 * Requires at least: 5.8
    88 * Requires PHP:      7.2
     
    5858});
    5959
    60 /*-------------------------------------------------
    61  3. Assets Enqueue
     60
     61/*-------------------------------------------------
     62 3. TEMPLATE METABOX
     63--------------------------------------------------*/
     64add_action( 'add_meta_boxes', function () {
     65
     66    add_meta_box(
     67        'rainbow_slider_template',
     68        __( 'Template', 'rainbow-slider' ),
     69        'rainbow_slider_template_box',
     70        'rainbow_slider',
     71        'side',
     72        'default'
     73    );
     74
     75});
     76
     77function rainbow_slider_template_box( $post ) {
     78
     79    wp_nonce_field( 'rainbow_slider_template', 'rainbow_slider_template_nonce' );
     80
     81    $current = get_post_meta( $post->ID, '_wp_page_template', true );
     82    if ( ! $current ) {
     83        $current = 'default';
     84    }
     85
     86    // Theme + Elementor templates (NO duplicate)
     87    $templates = wp_get_theme()->get_page_templates();
     88
     89    echo '<select name="rainbow_slider_template" style="width:100%">';
     90    echo '<option value="default">Default</option>';
     91
     92    foreach ( $templates as $file => $name ) {
     93        echo '<option value="' . esc_attr( $file ) . '"' .
     94             selected( $current, $file, false ) . '>' .
     95             esc_html( $name ) .
     96             '</option>';
     97    }
     98
     99    echo '</select>';
     100}
     101
     102
     103
     104/*-------------------------------------------------
     105 4. SAVE TEMPLATE
     106--------------------------------------------------*/
     107add_action( 'save_post_rainbow_slider', function ( $post_id ) {
     108
     109    if ( ! isset( $_POST['rainbow_slider_template_nonce'] ) ) return;
     110    if ( ! wp_verify_nonce( $_POST['rainbow_slider_template_nonce'], 'rainbow_slider_template' ) ) return;
     111
     112    if ( isset( $_POST['rainbow_slider_template'] ) ) {
     113        update_post_meta(
     114            $post_id,
     115            '_wp_page_template',
     116            sanitize_text_field( $_POST['rainbow_slider_template'] )
     117        );
     118    }
     119});
     120
     121
     122
     123/*-------------------------------------------------
     124 5. APPLY TEMPLATE ON FRONTEND
     125--------------------------------------------------*/
     126add_filter( 'template_include', function ( $template ) {
     127
     128    if ( is_singular( 'rainbow_slider' ) ) {
     129
     130        $tpl = get_post_meta( get_queried_object_id(), '_wp_page_template', true );
     131
     132        if ( $tpl === 'elementor_canvas' ) {
     133            return ELEMENTOR_PATH . 'modules/page-templates/templates/canvas.php';
     134        }
     135
     136        if ( $tpl === 'elementor_header_footer' ) {
     137            return ELEMENTOR_PATH . 'modules/page-templates/templates/header-footer.php';
     138        }
     139
     140        if ( $tpl && $tpl !== 'default' ) {
     141            $located = locate_template( $tpl );
     142            if ( $located ) return $located;
     143        }
     144    }
     145
     146    return $template;
     147});
     148
     149/*-------------------------------------------------
     150 6. Assets Enqueue
    62151--------------------------------------------------*/
    63152function rainbow_slider_assets() {
     
    137226
    138227/*-------------------------------------------------
    139  4. RENDER FUNCTION (The CSS Fix)
     228 7. RENDER FUNCTION (The CSS Fix)
    140229--------------------------------------------------*/
    141230function get_rainbow_slider_view( $post_id ) {
     
    180269
    181270/*-------------------------------------------------
    182  5. Widget Registration
     271 8. Widget Registration
    183272--------------------------------------------------*/
    184273add_action( 'elementor/elements/categories_registered', function( $elements_manager ) {
  • rainbow-slider/trunk/readme.txt

    r3423134 r3423195  
    44Requires at least: 5.8
    55Tested up to: 6.9
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77Requires PHP: 7.2
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.