Skip to content

Commit

Permalink
Merge pull request #131 from sesamyab/ma/paywall-wizard-default
Browse files Browse the repository at this point in the history
fix: change to use sesamy paywall wizard config
  • Loading branch information
markusahlstrand authored Aug 12, 2024
2 parents b8bc9d1 + 92c649c commit 4f1d814
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 313 deletions.
80 changes: 10 additions & 70 deletions src/admin/class-sesamy-settings-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,76 +146,16 @@ public function add_settings() {
);

add_settings_field(
'sesamy_paywall_wizard',
__( 'Use paywall wizard by default', 'sesamy' ),
array( $this, 'settings_render_boolean' ),
'sesamy',
'sesamy_section_general',
array(
'name' => 'sesamy_paywall_wizard',
'label_for' => 'sesamy_paywall_wizard',
)
);

add_settings_field(
'sesamy_paywall_wizard_logo_url',
__( 'Paywall Wizard Logo URL', 'sesamy' ),
array( $this, 'settings_render_input' ),
'sesamy',
'sesamy_section_general',
array(
'name' => 'sesamy_paywall_wizard_logo_url',
'label_for' => 'sesamy_paywall_wizard_logo_url',
)
);

add_settings_field(
'sesamy_paywall_wizard_logo_url',
__( 'Paywall Wizard Logo URL', 'sesamy' ),
array( $this, 'settings_render_input' ),
'sesamy',
'sesamy_section_general',
array(
'name' => 'sesamy_paywall_wizard_logo_url',
'label_for' => 'sesamy_paywall_wizard_logo_url',
)
);

add_settings_field(
'sesamy_paywall_wizard_title',
__( 'Paywall Wizard Title', 'sesamy' ),
array( $this, 'settings_render_input' ),
'sesamy',
'sesamy_section_general',
array(
'name' => 'sesamy_paywall_wizard_title',
'label_for' => 'sesamy_paywall_wizard_title',
)
);

add_settings_field(
'sesamy_paywall_wizard_perks',
__( 'Paywall Wizard Perks (One per line)', 'sesamy' ),
array( $this, 'settings_render_textarea' ),
'sesamy',
'sesamy_section_general',
array(
'name' => 'sesamy_paywall_wizard_perks',
'label_for' => 'sesamy_paywall_wizard_perks',
)
);

add_settings_field(
'sesamy_paywall_wizard_description',
__( 'Paywall Wizard Single Purchase Description', 'sesamy' ),
array( $this, 'settings_render_textarea' ),
'sesamy',
'sesamy_section_general',
array(
'name' => 'sesamy_paywall_wizard_description',
'label_for' => 'sesamy_paywall_wizard_description',
)
);
'sesamy_paywall_url',
__( 'Paywall URL', 'sesamy' ),
array( $this, 'settings_render_input' ),
'sesamy',
'sesamy_section_general',
array(
'name' => 'sesamy_paywall_url',
'label_for' => 'sesamy_paywall_url',
)
);
}

/**
Expand Down
92 changes: 29 additions & 63 deletions src/admin/gutenberg/sesamy-post-editor/src/sesamyPostEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
SelectControl,
CheckboxControl,
__experimentalInputControl as InputControl,
TextareaControl,
} from "@wordpress/components";
import { PluginDocumentSettingPanel } from "@wordpress/edit-post";
import { useSelect, useDispatch } from "@wordpress/data";
Expand Down Expand Up @@ -46,6 +45,8 @@ export default () => {
* @returns
*/
const SesamyPostEditor = () => {
const [isOverrideEnabled, setIsOverrideEnabled] = useState(false);

const meta = useSelect((select) =>
select("core/editor").getEditedPostAttribute("meta")
);
Expand Down Expand Up @@ -140,14 +141,10 @@ const SesamyPostEditor = () => {
return sesamyTiersTaxonomy.length > 0;
}, [sesamyTiersTaxonomy]);

// Populate payment types
const paymentTypes = useMemo(() => {
if (enableTiers === undefined) {
return;
}

return Array.from(getPaymentOptions(enableTiers));
}, [enableTiers]);
useEffect(() => {
const savedOverride = meta["_sesamy_paywall_url_override"];
setIsOverrideEnabled(savedOverride !== "");
}, [meta["_sesamy_paywall_url_override"]]);

// Enable tag if there is at least one
const enableSesamyTag = useMemo(() => {
Expand Down Expand Up @@ -335,64 +332,33 @@ const SesamyPostEditor = () => {

<h3>Paywall</h3>
<ToggleControl
checked={meta["_sesamy_show_login"]}
label={__("Show login", "sesamy")}
onChange={(value) => setMeta({ _sesamy_show_login: value })}
/>

<ToggleControl
checked={meta["_sesamy_paywall_wizard"]}
label={__("Use Paywall Wizard", "sesamy")}
onChange={(value) => setMeta({ _sesamy_paywall_wizard: value })}
checked={isOverrideEnabled}
label={__("Override default Paywall URL", "sesamy")}
onChange={(value) => {
setIsOverrideEnabled(value);
if (!value) {
setMeta({ _sesamy_paywall_url_override: "" });
} else {
setMeta({
_sesamy_paywall_url_override:
meta["_sesamy_paywall_url_override"] ||
sesamy_block_obj.paywall_url ||
"",
});
}
}}
/>

{meta["_sesamy_paywall_wizard"] && (
<ToggleControl
checked={meta["_sesamy_paywall_wizard_override_default"]}
label={__("Override Paywall Wizard default values", "sesamy")}
onChange={(value) =>
setMeta({ _sesamy_paywall_wizard_override_default: value })
}
{isOverrideEnabled && (
<InputControl
label={__("Override Paywall URL", "sesamy")}
value={meta["_sesamy_paywall_url_override"]}
onChange={(value) => {
setMeta({ _sesamy_paywall_url_override: value });
setIsOverrideEnabled(value !== "");
}}
/>
)}

{meta["_sesamy_paywall_wizard_override_default"] && (
<>
<InputControl
label={__("Logo URL", "sesamy")}
value={meta["_sesamy_paywall_wizard_logo_url"]}
onChange={(value) => {
setMeta({ _sesamy_paywall_wizard_logo_url: value });
}}
/>

<InputControl
label={__("Title", "sesamy")}
value={meta["_sesamy_paywall_wizard_title"]}
onChange={(value) => {
setMeta({ _sesamy_paywall_wizard_title: value });
}}
/>

<TextareaControl
label={__("Perks (One per line)", "sesamy")}
value={meta["_sesamy_paywall_wizard_perks"]}
onChange={(value) => {
setMeta({ _sesamy_paywall_wizard_perks: value });
}}
/>

{meta["_sesamy_enable_single_purchase"] && (
<TextareaControl
label={__("Single Purchase Description", "sesamy")}
value={meta["_sesamy_paywall_wizard_description"]}
onChange={(value) => {
setMeta({ _sesamy_paywall_wizard_description: value });
}}
/>
)}
</>
)}
</PluginDocumentSettingPanel>
);
};
73 changes: 3 additions & 70 deletions src/includes/class-sesamy-post-properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,76 +144,14 @@ public function register_post_meta() {

register_post_meta(
$post_type,
'_sesamy_paywall_wizard',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
'default' => $sesamy_paywall_wizard_option,
'auth_callback' => '__return_true',
)
);

register_post_meta(
$post_type,
'_sesamy_paywall_wizard_override_default',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
'default' => false,
'auth_callback' => '__return_true',
)
);

register_post_meta(
$post_type,
'_sesamy_paywall_wizard_logo_url',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'auth_callback' => '__return_true',
'default' => get_option( 'sesamy_paywall_wizard_logo_url' ),
)
);

register_post_meta(
$post_type,
'_sesamy_paywall_wizard_title',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'auth_callback' => '__return_true',
'default' => get_option( 'sesamy_paywall_wizard_title' ),
)
);

register_post_meta(
$post_type,
'_sesamy_paywall_wizard_perks',
'_sesamy_paywall_url_override',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'auth_callback' => '__return_true',
'default' => get_option( 'sesamy_paywall_wizard_perks' ),
)
);

register_post_meta(
$post_type,
'_sesamy_paywall_wizard_description',
array(
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'auth_callback' => '__return_true',
'default' => get_option( 'sesamy_paywall_wizard_description' ),
)
);

}
}
}
Expand Down Expand Up @@ -316,13 +254,8 @@ public static function get_post_settings( $post_id ) {
'locked_until' => (int) get_post_meta( $post->ID, '_sesamy_locked_until', true ),
'sesamy_tags' => get_post_meta( $post->ID, '_sesamy_tags', true ),
'access_level' => get_post_meta( $post->ID, '_sesamy_access_level', true ),
'paywall_wizard' => (bool) get_post_meta( $post->ID, '_sesamy_paywall_wizard', true ),
'paywall_wizard_override_default' => (bool) get_post_meta( $post->ID, '_sesamy_paywall_wizard_override_default', true ),
'paywall_wizard_logo_url' => get_post_meta( $post->ID, '_sesamy_paywall_wizard_logo_url', true ),
'paywall_wizard_title' => get_post_meta( $post->ID, '_sesamy_paywall_wizard_title', true ),
'paywall_wizard_description' => get_post_meta( $post->ID, '_sesamy_paywall_wizard_description', true ),
'paywall_wizard_perks' => get_post_meta( $post->ID, '_sesamy_paywall_wizard_perks', true ),
'show_login' => get_post_meta( $post->ID, '_sesamy_show_login', true ),
'show_login' => get_post_meta( $post->ID, '_sesamy_show_login', true ),
'paywall_url_override' => get_post_meta($post->ID, '_sesamy_paywall_url_override', true),
);
}
}
7 changes: 3 additions & 4 deletions src/includes/class-sesamy-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ public function register_settings() {
register_setting( 'sesamy', 'sesamy_content_types' );
register_setting( 'sesamy', 'sesamy_tags' );
register_setting( 'sesamy', 'sesamy_client_id' );
register_setting( 'sesamy', 'sesamy_paywall_url' );
register_setting( 'sesamy', 'sesamy_paywall_wizard',
array(
'type' => 'boolean',
'sanitize_callback' => 'rest_sanitize_boolean',
'default' => false, // Default value must be a boolean
) );
register_setting( 'sesamy', 'sesamy_paywall_wizard_logo_url' );
register_setting( 'sesamy', 'sesamy_paywall_wizard_title' );
register_setting( 'sesamy', 'sesamy_paywall_wizard_description' );
register_setting( 'sesamy', 'sesamy_paywall_wizard_perks' );

}

/**
Expand All @@ -61,6 +59,7 @@ public function get_public_settings() {

return array(
'content_types' => $this->get_content_types(),
'paywall_url' => get_option( 'sesamy_paywall_url', '' ),
);
}

Expand Down
Loading

0 comments on commit 4f1d814

Please sign in to comment.