Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/dlx-pw-patterns-view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-blob', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-escape-html', 'wp-i18n', 'wp-primitives', 'wp-private-apis', 'wp-url', 'wp-warning'), 'version' => '3c7f9bfaf7c367224e12');
<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-a11y', 'wp-api-fetch', 'wp-blob', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-date', 'wp-element', 'wp-escape-html', 'wp-i18n', 'wp-primitives', 'wp-private-apis', 'wp-url', 'wp-warning'), 'version' => '2f7f43587bd5a6709e98');
14 changes: 7 additions & 7 deletions build/dlx-pw-patterns-view.js

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions php/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,17 +576,19 @@ public function enqueue_admin_scripts_patterns() {
'dlx-pw-patterns-view',
'dlxEnhancedPatternsView',
array(
'getNonce' => wp_create_nonce( 'dlx-pw-patterns-view-get-patterns' ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
'createNonce' => wp_create_nonce( 'dlx-pw-patterns-view-create-pattern' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'options' => $options,
'networkOptions' => Options::get_network_options(),
'isMultisite' => is_multisite(),
'networkAdminSettingsUrl' => Functions::get_network_settings_url(),
'isUserNetworkAdmin' => current_user_can( 'manage_network' ),
'getSiteBaseUrl' => esc_url( admin_url() ),
'doNotShowAgain' => get_user_meta( get_current_user_id(), 'dlx_pw_do_not_show_again', true ) ?? false,
'getNonce' => wp_create_nonce( 'dlx-pw-patterns-view-get-patterns' ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
'createNonce' => wp_create_nonce( 'dlx-pw-patterns-view-create-pattern' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'options' => $options,
'networkOptions' => Options::get_network_options(),
'isMultisite' => is_multisite(),
'networkAdminSettingsUrl' => Functions::get_network_settings_url(),
'isUserNetworkAdmin' => current_user_can( 'manage_network' ),
'getSiteBaseUrl' => esc_url( admin_url() ),
'doNotShowAgain' => get_user_meta( get_current_user_id(), 'dlx_pw_do_not_show_again', true ) ?? false,
'syncedPatternPopupsActive' => Functions::is_activated( 'synced-pattern-popups/sppopups.php' ),
'syncedPatternPopupsUrl' => esc_url_raw( admin_url( 'themes.php?page=simplest-popup-patterns' ) ),
)
);
\wp_set_script_translations( 'dlx-pw-patterns-view', 'pattern-wrangler' );
Expand Down
12 changes: 10 additions & 2 deletions php/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,16 @@ public static function get_network_settings_url( $tab = '', $sub_tab = '' ) {
public static function is_activated( $path, $type = 'plugin' ) {

// Gets all active plugins on the current site.
$active_plugins = self::is_multisite() ? get_site_option( 'active_sitewide_plugins' ) : get_option( 'active_plugins', array() );
if ( in_array( $path, $active_plugins, true ) ) {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}

if ( is_multisite() ) {
if ( is_plugin_active_for_network( $path ) ) {
return true;
}
}
if ( is_plugin_active( $path ) ) {
return true;
}
return false;
Expand Down
98 changes: 83 additions & 15 deletions src/js/react/views/patterns/components/PatternGetCodeModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,25 @@
import React, { useState, useEffect } from 'react';
import { TextControl, Modal, Button } from '@wordpress/components';

import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';

/**
* Pattern Create Modal.
*
* @param {Object} props The props.
* @param {string} props.title The title of the modal.
* @param {string} props.patternId The id of the pattern.
* @param {string} props.patternNonce The nonce of the pattern.
* @param {string} props.patternTitle The title of the pattern.
* @param {Array} props.patternCategories The categories of the pattern in label arrays.
* @param {string} props.patternSyncStatus The sync status of the pattern.
* @param {string} props.patternCopyId The id of the pattern to copy.
* @param {Object} props.categories The categories of all the patterns..
* @param {Function} props.onRequestClose The function to call when the modal is closed.
* @param {string} props.syncedDefaultStatus The default sync status of the pattern. Values are 'synced' or 'unsynced'.
* @param {boolean} props.syncedDisabled Whether the synced status is disabled.
* @param {Function} props.onEdit The function to call when the pattern is edited.
* @param {Object} props The props.
* @param {Object} props.items The items to get the code for. Should be an array of one item.
* @param {Function} props.onRequestClose The function to call when the modal is closed.
* @return {Object} The rendered component.
*/
const PatternGetCodeModal = ( props ) => {
const { item } = props;
const { id = 0, syncStatus = 'unsynced' } = item || {};

const [ isMultisite ] = useState( dlxEnhancedPatternsView.isMultisite );
const [ shortcodeInputRef, setShortcodeInputRef ] = useState( null );
const [ phpFunctionInputRef, setPhpFunctionInputRef ] = useState( null );

const [ popupTriggerInputRef, setPopupTriggerInputRef ] = useState( null );
const [ popupTriggerAnchorInputRef, setPopupTriggerAnchorInputRef ] = useState( null );
const addCopyClipboardButton = async( inputRef, text ) => {
const copyButton = document.createElement( 'button' );
copyButton.classList.add( 'dlx-pw-copy-shortcode' );
Expand Down Expand Up @@ -110,6 +104,32 @@ const PatternGetCodeModal = ( props ) => {
addCopyClipboardButton( phpFunctionInputRef, getPatternPHPFunction() );
}, [ phpFunctionInputRef ] );

/**
* Copy the popup trigger code to the clipboard when the popup trigger input is focused.
*
* @return {void}
*/
useEffect( () => {
if ( ! popupTriggerInputRef ) {
return;
}

addCopyClipboardButton( popupTriggerInputRef, getPatternPopupTriggerCode() );
}, [ popupTriggerInputRef ] );

/**
* Copy the popup trigger anchor code to the clipboard when the popup trigger anchor input is focused.
*
* @return {void}
*/
useEffect( () => {
if ( ! popupTriggerAnchorInputRef ) {
return;
}

addCopyClipboardButton( popupTriggerAnchorInputRef, getPatternPopupTriggerAnchorCode() );
}, [ popupTriggerAnchorInputRef ] );

/**
* Get the modal title.
*
Expand All @@ -131,6 +151,14 @@ const PatternGetCodeModal = ( props ) => {
return `[wp_block slug="${ props.item.slug }"]`;
};

const getPatternPopupTriggerCode = () => {
return `spp-trigger-${ id }`;
};

const getPatternPopupTriggerAnchorCode = () => {
return `<a href="#spp-trigger-${ id }">Open the Popup</a>`;
};

/**
* Get the pattern PHP function.
*
Expand Down Expand Up @@ -174,6 +202,46 @@ const PatternGetCodeModal = ( props ) => {
className="dlx-pw-modal-admin-row-input"
/>
</div>
{ dlxEnhancedPatternsView.syncedPatternPopupsActive &&
syncStatus === 'synced' && (
<>
<div className="dlx-pw-modal-admin-row">
<TextControl
label={ __(
'Synced Patterns Popup Trigger Code',
'pattern-wrangler'
) }
value={ getPatternPopupTriggerCode() }
disabled={ true }
ref={ setPopupTriggerInputRef }
className="dlx-pw-modal-admin-row-input"
help={ __(
'This is the code to trigger the Synced Pattern Popup on your site.',
'pattern-wrangler'
) }
/>
<TextControl
label={ __(
'Synced Patterns Popup Trigger Anchor Code',
'pattern-wrangler'
) }
value={ getPatternPopupTriggerAnchorCode() }
disabled={ true }
ref={ setPopupTriggerAnchorInputRef }
className="dlx-pw-modal-admin-row-input"
help={ __(
'This is the code to add to the anchor of the Synced Pattern Popup on your site.',
'pattern-wrangler'
) }
/>
<p className="description">
<a href={ `${ dlxEnhancedPatternsView.syncedPatternPopupsUrl }#how-to-use` } target="_blank" rel="noreferrer">
{ __( 'Synced Patterns Popup documentation', 'pattern-wrangler' ) }
</a>
</p>
</div>
</>
) }
<div className="dlx-pw-modal-admin-row dlx-pw-modal-admin-row-buttons">
<Button variant="secondary" onClick={ props.onRequestClose }>
{ __( 'Cancel', 'pattern-wrangler' ) }
Expand Down