$template ) { Templates::update_templates( $index, Templates::sanitize_editor( $template ) ); } Settings::redirect_with_message( $redirect, 9 ); } /** * Action to clone template. */ public static function clone_template() { check_admin_referer( Settings::SETTINGS_NONCE, 'sharing_image_nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to manage options for this site.', 'sharing-image' ) ); } $redirect = Settings::get_tab_link( 'tools' ); if ( ! isset( $_REQUEST['sharing_image_source'] ) ) { Settings::redirect_with_message( $redirect, 10 ); } $index = sanitize_key( $_REQUEST['sharing_image_source'] ); // Get all templates to find by index. $templates = Templates::get_templates(); if ( ! isset( $templates[ $index ] ) ) { Settings::redirect_with_message( $redirect, 10 ); } $template = $templates[ $index ]; // Remove poster if exists. unset( $template['preview'] ); if ( empty( $template['title'] ) ) { $template['title'] = esc_html__( 'Untitled', 'sharing-image' ); } $prefix = esc_html__( 'Copy: ' ); if ( strpos( $template['title'], $prefix ) !== 0 ) { $template['title'] = $prefix . $template['title']; } $layers = array(); foreach ( $template['layers'] as $layer ) { $key = Templates::generate_layer_key(); $layers[ $key ] = $layer; } $template['layers'] = $layers; if ( ! Templates::update_templates( Templates::create_unique_index(), $template ) ) { Settings::redirect_with_message( $redirect, 10 ); } Settings::redirect_with_message( $redirect, 11 ); } /** * Action to clear templates data. */ public static function clear_templates() { check_admin_referer( Settings::SETTINGS_NONCE, 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Sorry, you do not have permission to manage options for this site.', 'sharing-image' ) ); } $redirect = Settings::get_tab_link( 'tools' ); delete_metadata( 'post', null, Widget::META_SOURCE, '', true ); delete_metadata( 'post', null, Widget::META_FIELDSET, '', true ); delete_metadata( 'term', null, Widget::META_SOURCE, '', true ); delete_metadata( 'term', null, Widget::META_FIELDSET, '', true ); Settings::redirect_with_message( $redirect, 12 ); } }