Skip to content

Commit

Permalink
Merge pull request #75 from XjSv/develop
Browse files Browse the repository at this point in the history
More Changes for v1.8.8
  • Loading branch information
XjSv authored Nov 14, 2024
2 parents b33e9af + 4a12c96 commit a9b43fa
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 252 deletions.
41 changes: 21 additions & 20 deletions includes/class.cooked-recipe-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ public static function meta_cleanup( $recipe_settings ) {
global $_cooked_settings;
$_recipe_settings = [];

if ( class_exists( 'Cooked_Pro_Plugin' ) ) {
$wp_editor_roles_allowed = false;
if (is_user_logged_in()) {
$user = wp_get_current_user();
$user_role = $user->roles[0];
$wp_editor_roles_allowed = isset( $_cooked_settings['recipe_submission_wp_editor_roles'] ) && in_array( $user_role, $_cooked_settings['recipe_submission_wp_editor_roles'] ) ? true : false;
}
} else {
$wp_editor_roles_allowed = true;
$wp_editor_roles_allowed = false;
if (is_user_logged_in()) {
$user = wp_get_current_user();
$user_role = $user->roles[0];
$wp_editor_roles_allowed = isset( $_cooked_settings['recipe_wp_editor_roles'] ) && in_array( $user_role, $_cooked_settings['recipe_wp_editor_roles'] ) ? true : false;
}

if (!empty($recipe_settings)):
foreach ($recipe_settings as $key => $val):
if (!is_array($val)):
if ( $key === "content" || $key === "excerpt" || $key === "notes" ):
$_recipe_settings[$key] = wp_kses_post( $val );
if ($wp_editor_roles_allowed) {
$_recipe_settings[$key] = wp_kses_post( $val );
} else {
$_recipe_settings[$key] = Cooked_Functions::sanitize_text_field( $val );
}
else:
$_recipe_settings[$key] = Cooked_Functions::sanitize_text_field( $val );
endif;
Expand All @@ -54,7 +54,12 @@ public static function meta_cleanup( $recipe_settings ) {
foreach ( $subval as $sub_subkey => $sub_subval ):
if ( !is_array($sub_subval) ):
if ( $sub_subkey == 'content' || $key == 'ingredients' && $sub_subkey == 'name' || $key == 'ingredients' && $sub_subkey == 'section_heading_name' || $key == 'directions' && $sub_subkey == 'section_heading_name' ):
$_recipe_settings[$key][$subkey][$sub_subkey] = wp_kses_post( $sub_subval );

if ($wp_editor_roles_allowed) {
$_recipe_settings[$key][$subkey][$sub_subkey] = wp_kses_post( $sub_subval );
} else {
$_recipe_settings[$key][$subkey][$sub_subkey] = Cooked_Functions::sanitize_text_field( $sub_subval );
}
else:
$_recipe_settings[$key][$subkey][$sub_subkey] = Cooked_Functions::sanitize_text_field( $sub_subval );
endif;
Expand Down Expand Up @@ -245,15 +250,11 @@ function cooked_render_recipe_fields( $post_id ) {

$measurements = Cooked_Measurements::get();

if ( class_exists( 'Cooked_Pro_Plugin' ) ) {
$wp_editor_roles_allowed = false;
if (is_user_logged_in()) {
$user = wp_get_current_user();
$user_role = $user->roles[0];
$wp_editor_roles_allowed = isset( $_cooked_settings['recipe_submission_wp_editor_roles'] ) && in_array( $user_role, $_cooked_settings['recipe_submission_wp_editor_roles'] ) ? true : false;
}
} else {
$wp_editor_roles_allowed = true;
$wp_editor_roles_allowed = false;
if (is_user_logged_in()) {
$user = wp_get_current_user();
$user_role = $user->roles[0];
$wp_editor_roles_allowed = isset( $_cooked_settings['recipe_wp_editor_roles'] ) && in_array( $user_role, $_cooked_settings['recipe_wp_editor_roles'] ) ? true : false;
}

/* $cooked_page_args = [
Expand Down
37 changes: 24 additions & 13 deletions includes/class.cooked-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ public static function get() {
foreach ( $tab['fields'] as $name => $field ) {
if ( $field['type'] == 'nonce' || $field['type'] == 'misc_button' ) continue;

if ( $field['type'] == 'checkboxes' && $cooked_settings_saved && $version_compare >= 0 ) {
$_cooked_settings[$name] = isset($_cooked_settings[$name]) ? $_cooked_settings[$name] : [];
} else {
$_cooked_settings[$name] = isset($_cooked_settings[$name]) ? $_cooked_settings[$name] : ( isset( $field['default'] ) ? $field['default'] : false );
if ( $cooked_settings_saved && $version_compare >= 0 ) {
if ( $field['type'] == 'checkboxes' ) {
$_cooked_settings[$name] = isset($_cooked_settings[$name]) ? $_cooked_settings[$name] : ( isset( $field['default'] ) ? $field['default'] : [] );
} else {
$_cooked_settings[$name] = isset($_cooked_settings[$name]) ? $_cooked_settings[$name] : ( isset( $field['default'] ) ? $field['default'] : false );
}

// Update the settings only if the version has changed.
$update_settings = true;
}
}
Expand Down Expand Up @@ -237,11 +241,10 @@ public static function tabs_fields() {
]
)
],
'recipe_submission_wp_editor_roles' => [
'title' => __('WP Editor Roles', 'cooked-pro'),
'desc' => __('Choose which user roles can use the WP Editor for the Excerpt, Directions & Notes fields.', 'cooked-pro'),
'recipe_wp_editor_roles' => [
'title' => __('WP Editor Roles', 'cooked'),
'desc' => __('Choose which user roles can use the WP Editor for the Excerpt, Directions & Notes fields.', 'cooked'),
'type' => 'checkboxes',
'conditional_requirement' => 'enable_recipe_submissions',
'default' => apply_filters('cooked_add_recipe_wp_editor_roles_defaults', ['administrator', 'editor', 'cooked_recipe_editor']),
'options' => $role_options
],
Expand Down Expand Up @@ -376,7 +379,7 @@ public static function per_page_array() {
return apply_filters( 'cooked_per_page_options', $per_page_array );
}

public static function pages_array( $choose_text,$none_text = false ) {
public static function pages_array( $choose_text, $none_text = false ) {
$page_array = [];
$pages = get_posts([
'post_type' => 'page',
Expand All @@ -386,7 +389,7 @@ public static function pages_array( $choose_text,$none_text = false ) {
if( !empty($pages) ) {
$page_array[0] = $choose_text;
foreach ($pages as $_page) {
$page_array[$_page->ID] = $_page->post_title;
$page_array[$_page->ID] = $_page->post_title . ' (ID:' . $_page->ID . ')';
}
} elseif ( $none_text ) {
$page_array[0] = $none_text;
Expand Down Expand Up @@ -575,7 +578,7 @@ public static function field_color_field( $field_name, $default ) {
echo '</p>';
}

public static function field_checkboxes( $field_name, $options, $color = false ) {
public static function field_checkboxes( $field_name, $options, $color = false, $field = [] ) {
global $_cooked_settings, $conditions;

echo '<p class="cooked-padded">';
Expand Down Expand Up @@ -615,9 +618,17 @@ public static function field_checkboxes( $field_name, $options, $color = false )

if ( $is_disabled ):
echo '<input type="hidden" name="cooked_settings[' . esc_attr( $field_name ) . '][]" value="' . esc_attr( $value ) . '">';
echo '<input' . $combined_extras . ' class="cooked-switch' . ( $color ? '-' . esc_attr( $color ) : '' ) . '" type="checkbox" id="checkbox-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '"' . ( isset( $_cooked_settings[$field_name] ) && !empty($_cooked_settings[$field_name]) && in_array( $value, $_cooked_settings[$field_name] ) || $is_disabled ? ' checked' : '' ) . '/>';
echo '<input' . $combined_extras . ' class="cooked-switch' . ( $color ? '-' . esc_attr( $color ) : '' ) . '" type="checkbox" id="checkbox-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '"' . (
(isset( $_cooked_settings[$field_name] ) && !empty($_cooked_settings[$field_name]) && in_array( $value, $_cooked_settings[$field_name] )) ||
$is_disabled ||
(empty($_cooked_settings[$field_name]) && isset($field['default']) && in_array($value, (array)$field['default']))
? ' checked' : '' ) . '/>';
else:
echo '<input' . $combined_extras . ' class="cooked-switch' . ( $color ? '-' . esc_attr( $color ) : '' ) . '" type="checkbox" id="checkbox-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '" name="cooked_settings[' . esc_attr( $field_name ) . '][]" value="' . esc_attr( $value ) . '"' . ( isset( $_cooked_settings[$field_name] ) && !empty($_cooked_settings[$field_name]) && is_array( $_cooked_settings[$field_name] ) && in_array( $value, $_cooked_settings[$field_name] ) || $is_disabled ? ' checked' : '' ) . '/>';
echo '<input' . $combined_extras . ' class="cooked-switch' . ( $color ? '-' . esc_attr( $color ) : '' ) . '" type="checkbox" id="checkbox-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '" name="cooked_settings[' . esc_attr( $field_name ) . '][]" value="' . esc_attr( $value ) . '"' . (
(isset( $_cooked_settings[$field_name] ) && !empty($_cooked_settings[$field_name]) && is_array( $_cooked_settings[$field_name] ) && in_array( $value, $_cooked_settings[$field_name] )) ||
$is_disabled ||
(empty($_cooked_settings[$field_name]) && isset($field['default']) && in_array($value, (array)$field['default']))
? ' checked' : '' ) . '/>';
endif;

echo '&nbsp;<label for="checkbox-group-' . esc_attr( $field_name ) . '-' . esc_attr( $value ) . '">' . wp_kses_post( $name ) . '</label>';
Expand Down
Loading

0 comments on commit a9b43fa

Please sign in to comment.