Dudaevskiy
1/18/2020 - 10:07 PM

Composer Redux 4

{
"require": {
    "composer/installers": "*",
    "reduxframework/redux-framework-4" : "^4.0"
},
"repositories": [
    {
        "type": "package",
        "package": {
            "name": "reduxframework/redux-framework-4",
            "type": "wordpress-plugin",
            "version": "4.0.1",
            "dist": {
                "type": "zip",
                 "url": "https://github.com/reduxframework/redux-framework-4/archive/master.zip"
            },
            "require" : {
                "composer/installers": "*"
            },
			"extra": {
				"installer-paths": {
					"vendor/{$name}/": ["type:wordpress-plugin"]
				}
			}
        }
    }
]
}
composer require reduxframework/redux-framework-4
<?php

//Download and Insert a Remote Image File into the WordPress Media Library
//https://kellenmace.com/download-insert-remote-image-file-wordpress-media-library/
// Require the file that contains the KM_Download_Remote_Image class.
require_once plugin_dir_path( __FILE__ ) . 'vendor/class-download-remote-image.php';
// Redux Framework
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';


if (!class_exists('ReduxFramework') && file_exists(plugin_dir_path(__FILE__) . 'wp-content/plugins/redux-framework-4/ReduxCore/framework.php')) {
//==========================================
//==========================================
// Подключаем Redux
    require_once plugin_dir_path( __FILE__ ) . '/wp-content/plugins/redux-framework-4/ReduxCore/framework.php';

//Redux::setSection($opt_name, array(    'title' => esc_html__('Section title', 'yourtextdomain') ,    'id' => esc_html__('section-unique-id', ' yourtextdomain') ,    'icon' => 'icon-name',    'fields' => array()));

//==========================================
//==========================================
}
if ( ! class_exists( 'Redux' ) ) {
    return null;
}


//-----------------------------------------
// REMOVE DEMO and PROMO REDUX
// START
//-----------------------------------------
/**
 * Disable Redux Developer Mode dev_mode
 * https://asique.net/disable-redux-framework-developer-mode-dev_mode/
 * START
 */

if ( !function_exists( 'redux_disable_dev_mode_plugin' ) ) {

    function redux_disable_dev_mode_plugin( $redux ) {
        if ( $redux->args[ 'opt_name' ] != 'redux_demo' ) {
            $redux->args[ 'dev_mode' ] = false;
            $redux->args[ 'forced_dev_mode_off' ] = false;
        }
    }

    add_action( 'redux/construct', 'redux_disable_dev_mode_plugin' );
}

function gl_removeDemoModeLink() {
    if ( class_exists( 'ReduxFrameworkPlugin' ) ) {
        remove_filter( 'plugin_row_meta', array( ReduxFrameworkPlugin::get_instance(), 'plugin_metalinks' ), null, 2 );
    }
    if ( class_exists( 'ReduxFrameworkPlugin' ) ) {
        remove_action( 'admin_notices', array( ReduxFrameworkPlugin::get_instance(), 'admin_notices' ) );
    }
}

add_action( 'init', 'gl_removeDemoModeLink' );
/**
 * END
 * Disable Redux Developer Mode dev_mode
 */
add_action( 'redux/loaded', 'remove_demo' );


/**
 * Removes the demo link and the notice of integrated demo from the redux-framework plugin
 * https://forums.envato.com/t/how-to-remove-redux-framework-notice/62645/4
 * START
 */
if ( ! function_exists( 'remove_demo' ) ) {
    function remove_demo() {
        // Used to hide the demo mode link from the plugin page. Only used when Redux is a plugin.
        if ( class_exists( 'ReduxFrameworkPlugin' ) ) {
            remove_filter( 'plugin_row_meta', array(
                ReduxFrameworkPlugin::instance(),
                'plugin_metalinks'
            ), null, 2 );

            // Used to hide the activation notice informing users of the demo panel. Only used when Redux is a plugin.
            remove_action( 'admin_notices', array( ReduxFrameworkPlugin::instance(), 'admin_notices' ) );
        }
    }
}
/**
 * END
 * Removes the demo link and the notice of integrated demo from the redux-framework plugin
 * https://forums.envato.com/t/how-to-remove-redux-framework-notice/62645/4
 */

/**
 * https://docs.reduxframework.com/core/the-basics/removing-demo-mode-and-notices/
 * START
 */
function removeDemoModeLink() { // Be sure to rename this function to something more unique
    if ( class_exists('ReduxFrameworkPlugin') ) {
        remove_filter( 'plugin_row_meta', array( ReduxFrameworkPlugin::get_instance(), 'plugin_metalinks'), null, 2 );
    }
    if ( class_exists('ReduxFrameworkPlugin') ) {
        remove_action('admin_notices', array( ReduxFrameworkPlugin::get_instance(), 'admin_notices' ) );
    }
}
add_action('init', 'removeDemoModeLink');
/**
 * END
 * https://docs.reduxframework.com/core/the-basics/removing-demo-mode-and-notices/
 */
//-----------------------------------------
// END
// REMOVE DEMO and PROMO REDUX
//-----------------------------------------



// This is your option name where all the Redux data is stored.
$opt_name = 'redux_sds_uapa_wpallimp';

/**
 * GLOBAL ARGUMENTS
 * All the possible arguments for Redux.
 * For full documentation on arguments, please refer to: @link https://github.com/ReduxFramework/ReduxFramework/wiki/Arguments
 */

/**
 * ---> BEGIN ARGUMENTS
 */

$theme = wp_get_theme(); // For use with some settings. Not necessary.

$args = array(
    // REQUIRED!!  Change these values as you need/desire.
    'opt_name'                  => $opt_name,

    // Name that appears at the top of your panel.
    'display_name'              => $theme->get( 'Name' ),

    // Version that appears at the top of your panel.
    'display_version'           => $theme->get( 'Version' ),

    // Specify if the admin menu should appear or not. Options: menu or submenu (Under appearance only).
    'menu_type'                 => 'menu',

    // Show the sections below the admin menu item or not.
    'allow_sub_menu'            => true,

    'menu_title'                => esc_html__( 'Sample Options', 'your-domain-here' ),
    'page_title'                => esc_html__( 'Sample Options', 'your-domain-here' ),

    // Use a asynchronous font on the front end or font string.
    'async_typography'          => true,

    // Disable this in case you want to create your own google fonts loader.
    'disable_google_fonts_link' => false,

    // Show the panel pages on the admin bar.
    'admin_bar'                 => true,

    // Choose an icon for the admin bar menu.
    'admin_bar_icon'            => 'dashicons-portfolio',

    // Choose an priority for the admin bar menu.
    'admin_bar_priority'        => 50,

    // Set a different name for your global variable other than the opt_name.
    'global_variable'           => '',

    // Show the time the page took to load, etc.
    'dev_mode'                  => false,

    // Enable basic customizer support.
    'customizer'                => true,

    // Order where the menu appears in the admin area. If there is any conflict, something will not show. Warning.
    'page_priority'             => null,

    // For a full list of options, visit: @link http://codex.wordpress.org/Function_Reference/add_submenu_page#Parameters.
    'page_parent'               => 'themes.php',

    // Permissions needed to access the options panel.
    'page_permissions'          => 'manage_options',

    // Specify a custom URL to an icon.
    'menu_icon'                 => '',

    // Force your panel to always open to a specific tab (by id).
    'last_tab'                  => '',

    // Icon displayed in the admin panel next to your menu_title.
    'page_icon'                 => 'icon-themes',

    // Page slug used to denote the panel.
    'page_slug'                 => '_options',

    // On load save the defaults to DB before user clicks save or not.
    'save_defaults'             => true,

    // If true, shows the default value next to each field that is not the default value.
    'default_show'              => false,

    // What to print by the field's title if the value shown is default. Suggested: *.
    'default_mark'              => '',

    // Shows the Import/Export panel when not used as a field.
    'show_import_export'        => true,

    // CAREFUL -> These options are for advanced use only.
    'transient_time'            => 60 * MINUTE_IN_SECONDS,

    // Global shut-off for dynamic CSS output by the framework. Will also disable google fonts output.
    'output'                    => true,

    // Allows dynamic CSS to be generated for customizer and google fonts, but stops the dynamic CSS from going to the head.
    'output_tag'                => true,

    // FUTURE -> Not in use yet, but reserved or partially implemented. Use at your own risk.
    // possible: options, theme_mods, theme_mods_expanded, transient. Not fully functional, warning!
    'database'                  => '',

    // If you prefer not to use the CDN for Select2, Ace Editor, and others, you may download the Redux Vendor Support plugin yourself and run locally or embed it in your code.
    'use_cdn'                   => true,
    'compiler'                  => true,

    // HINTS.
    'hints'                     => array(
        'icon'          => 'el el-question-sign',
        'icon_position' => 'right',
        'icon_color'    => 'lightgray',
        'icon_size'     => 'normal',
        'tip_style'     => array(
            'color'   => 'light',
            'shadow'  => true,
            'rounded' => false,
            'style'   => '',
        ),
        'tip_position'  => array(
            'my' => 'top left',
            'at' => 'bottom right',
        ),
        'tip_effect'    => array(
            'show' => array(
                'effect'   => 'slide',
                'duration' => '500',
                'event'    => 'mouseover',
            ),
            'hide' => array(
                'effect'   => 'slide',
                'duration' => '500',
                'event'    => 'click mouseleave',
            ),
        ),
    ),
);

// ADMIN BAR LINKS -> Setup custom links in the admin bar menu as external items.
$args['admin_bar_links'][] = array(
    'id'    => 'redux-docs',
    'href'  => '//docs.reduxframework.com/',
    'title' => esc_html__( 'Documentation', 'your-domain-here' ),
);

$args['admin_bar_links'][] = array(
    'id'    => 'redux-support',
    'href'  => '//github.com/ReduxFramework/redux-framework/issues',
    'title' => esc_html__( 'Support', 'your-domain-here' ),
);

$args['admin_bar_links'][] = array(
    'id'    => 'redux-extensions',
    'href'  => 'reduxframework.com/extensions',
    'title' => esc_html__( 'Extensions', 'your-domain-here' ),
);

// SOCIAL ICONS -> Setup custom links in the footer for quick links in your panel footer icons.
$args['share_icons'][] = array(
    'url'   => '//github.com/ReduxFramework/ReduxFramework',
    'title' => 'Visit us on GitHub',
    'icon'  => 'el el-github',
);
$args['share_icons'][] = array(
    'url'   => '//www.facebook.com/pages/Redux-Framework/243141545850368',
    'title' => esc_html__( 'Like us on Facebook', 'your-domain-here' ),
    'icon'  => 'el el-facebook',
);
$args['share_icons'][] = array(
    'url'   => '//twitter.com/reduxframework',
    'title' => esc_html__( 'Follow us on Twitter', 'your-domain-here' ),
    'icon'  => 'el el-twitter',
);
$args['share_icons'][] = array(
    'url'   => '//www.linkedin.com/company/redux-framework',
    'title' => esc_html__( 'FInd us on LinkedIn', 'your-domain-here' ),
    'icon'  => 'el el-linkedin',
);

// Panel Intro text -> before the form.
if ( ! isset( $args['global_variable'] ) || false !== $args['global_variable'] ) {
    if ( ! empty( $args['global_variable'] ) ) {
        $v = $args['global_variable'];
    } else {
        $v = str_replace( '-', '_', $args['opt_name'] );
    }
    $args['intro_text'] = '<p>' . sprintf( __( 'Did you know that Redux sets a global variable for you? To access any of your saved options from within your code you can use your global variable: $s', 'your-domain-here' ) . '</p>', '<strong>' . $v . '</strong>' );
} else {
    $args['intro_text'] = '<p>' . esc_html__( 'This text is displayed above the options panel. It isn\'t required, but more info is always better! The intro_text field accepts all HTML.', 'your-domain-here' ) . '</p>';
}

// Add content after the form.
$args['footer_text'] = '<p>' . esc_html__( 'This text is displayed below the options panel. It isn\'t required, but more info is always better! The footer_text field accepts all HTML.', 'your-domain-here' ) . '</p>';

Redux::set_args( $opt_name, $args );

/*
 * ---> END ARGUMENTS
 */

/*
 * ---> BEGIN HELP TABS
 */

$help_tabs = array(
    array(
        'id'      => 'redux-help-tab-1',
        'title'   => esc_html__( 'Theme Information 1', 'your-domain-here' ),
        'content' => '<p>' . esc_html__( 'This is the tab content, HTML is allowed.', 'your-domain-here' ) . '</p>',
    ),

    array(
        'id'      => 'redux-help-tab-2',
        'title'   => esc_html__( 'Theme Information 2', 'your-domain-here' ),
        'content' => '<p>' . esc_html__( 'This is the tab content, HTML is allowed.', 'your-domain-here' ) . '</p>',
    ),
);

Redux::set_help_tab( $opt_name, $help_tabs );

// Set the help sidebar.
$content = '<p>' . esc_html__( 'This is the sidebar content, HTML is allowed.', 'your-domain-here' ) . '</p>';
Redux::set_help_sidebar( $opt_name, $content );

/*
 * <--- END HELP TABS
 */

/*
 *
 * ---> BEGIN SECTIONS
 *
 */

/* As of Redux 3.5+, there is an extensive API. This API can be used in a mix/match mode allowing for. */

/* -> START Basic Fields. */

$kses_exceptions = array(
    'a'      => array(
        'href' => array(),
    ),
    'strong' => array(),
    'br'     => array(),
);

$section = array(
    'title'  => esc_html__( 'Basic Field', 'your-domain-here' ),
    'id'     => 'basic',
    'desc'   => esc_html__( 'Basic field with no subsections.', 'your-domain-here' ),
    'icon'   => 'el el-home',
    'fields' => array(
        array(
            'id'       => 'opt-text',
            'type'     => 'text',
            'title'    => esc_html__( 'Example Text', 'your-domain-here' ),
            'desc'     => esc_html__( 'Example description.', 'your-domain-here' ),
            'subtitle' => esc_html__( 'Example subtitle.', 'your-domain-here' ),
            'hint'     => array(
                'content' => wp_kses( __( 'This is a <strong>hint</strong> tool-tip for the text field.<br/><br/>Add any HTML based text you like here.', 'your-domain here' ), $kses_exceptions ),
            ),
        ),
    ),
);

Redux::set_section( $opt_name, $section );

$section = array(
    'title' => __( 'Basic Fields', 'your-domain-here' ),
    'id'    => 'basic',
    'desc'  => __( 'Basic fields as subsections.', 'your-domain-here' ),
    'icon'  => 'el el-home',
);

Redux::set_section( $opt_name, $section );

$section = array(
    'title'      => esc_html__( 'Text', 'your-domain-here' ),
    'desc'       => esc_html__( 'For full documentation on this field, visit: ', 'your-domain-here' ) . '<a href="//docs.reduxframework.com/core/fields/text/" target="_blank">//docs.reduxframework.com/core/fields/text/</a>',
    'id'         => 'opt-text-subsection',
    'subsection' => true,
    'fields'     => array(
        array(
            'id'       => 'text-example',
            'type'     => 'text',
            'title'    => esc_html__( 'Text Field', 'your-domain-here' ),
            'subtitle' => esc_html__( 'Subtitle', 'your-domain-here' ),
            'desc'     => esc_html__( 'Field Description', 'your-domain-here' ),
            'default'  => 'Default Text',
        ),
    ),
);

Redux::set_section( $opt_name, $section );

$section = array(
    'title'      => esc_html__( 'Text Area', 'your-domain-here' ),
    'desc'       => esc_html__( 'For full documentation on this field, visit: ', 'your-domain-here' ) . '<a href="//docs.reduxframework.com/core/fields/textarea/" target="_blank">//docs.reduxframework.com/core/fields/textarea/</a>',
    'id'         => 'opt-textarea-subsection',
    'subsection' => true,
    'fields'     => array(
        array(
            'id'       => 'textarea-example',
            'type'     => 'textarea',
            'title'    => esc_html__( 'Text Area Field', 'your-domain-here' ),
            'subtitle' => esc_html__( 'Subtitle', 'your-domain-here' ),
            'desc'     => esc_html__( 'Field Description', 'your-domain-here' ),
            'default'  => 'Default Text',
        ),
    ),
);

Redux::set_section( $opt_name, $section );

/*
 * <--- END SECTIONS
 */






// dd(get_post_meta(7013));
// dd(get_post(7009));
//Обновление всех постов
function update_all_posts() {
    $args = array(
        'post_type' => 'post',
        // 'numberposts' => -1

		'post__in' => array(7043)
    );
    $all_posts = get_posts($args);
	
	
	// Указываем плагину Mrkdown загружать все изображения
	// $_POST['fetch_remote_image'] = 'yes';
	$_POST['markdown_this_post'] = 'yes';
	$_POST['h2m_strip_tags'] = 'no';
	$_POST['h2m_line_break'] = 'yes';
	
	$post_id = $_POST['post_ID'];
	// $_POST['post_ID'] = 'yes';
	// dd($_POST);
	
    foreach ($all_posts as $single_post){
		
		$post_id = $single_post->ID;
		$content = $single_post->post_content;
// https://cubewebsites.com/development/php/guide-find-and-replace-markdown-image-urls-in-php/
// Inline Style Images
$content    =   preg_replace_callback('/!\[(.*)\]\s?\((.*)(.png|.gif|.jpg|.jpeg)(.*)\)/',function($match){
    // return str_replace('your_search_term','your_replacement',$match[0]);
	// Ссылка на картинку
	$link_image = $match[2].$match[3];

	// dd($link_image);
},$content);

// Reference Style Images
// $content    =   preg_replace_callback('/\[(.*)\]:\s?(.*)(.png|.gif|.jpg|.jpeg)/',function($match){
    // return str_replace('your_search_term','your_replacement',$match[0]);
// },$content);


		// echo get_all_images($content);
		// dd(get_all_images($content));
		
		
        $single_post->post_title = $single_post->post_title.'';
		// Удаляем все изображения записи
		$single_post->post_content = preg_replace('/&lt;!-- this image post(.*)">--&gt;/', '', $single_post->post_content);
		// $single_post->post_content = preg_replace('/&lt;!-- this image post(.*)">--&gt;/', '', $single_post->post_content);
		// $single_post->post_content = convert_remote_image( $single_post->post_content  );
		// $fetchRemoteImage = new Controller\FetchRemoteImage();
		// $fetchRemoteImage->init();
		// $single_post->post_content  = FetchRemoteImage::covert( $post_content  );
					
					
					
        wp_update_post( $single_post );
    }
}
add_action( 'wp_loaded', 'update_all_posts' );


?>